2011-05-10 24 views
0

這可以被應用到許多不同的方案,但具體我運行:PowerShell:如何評估對象中的每個屬性?

Import-Csv "file.txt" | foreach { $_ } 

一般地,輸出的是:

Attribute1 : $true 
Attribute2 : asdf 
Attribute3 : {} 
Attribute4 : $true 

我怎麼可以運行一個foreach循環,我可以用它來比較每個屬性的名稱和值?例如,查看哪個屬性的值等於$ true,但不是屬性4。 (我打開使用其他的東西比的foreach,這只是我所知道的。)

我知道我能做到(Import-Csv "file.txt").Attribute1,但我那將是非常不切實際的做到這一點每個屬性。

這些屬性將是不同類型的變量(一些字符串,一些布爾值,一些數組),但我一次只會遇到一個問題。

編輯:
我不認爲這是相關的,但CSV文件從
Get-ActiveSyncMailboxPolicy -Identity "Policy" | Export-Csv

回答

4

Soemthing這樣來的?

Import-Csv "file.txt" | foreach-object { 
$_.psobject.properties | where-object { 
$_.value -eq $true -and $_.name -ne "Attribute4}