PowerShell: How to evaluate each attribute in an object?
This can be applied to many different scenarios, but specifically I am running:
Import-Csv "file.txt" | foreach { $_ }
Generically, the output is:
Attribute1 : $true
Attribute2 : asdf
Attribute3 : {}
Attribute4 : $true
How could I run a foreach loop that I could use to compare each attribute's name and value? For example see which attribute's equal $true but isn't Attribute4. (I'm open to using something other than foreach, that's just all I know.)
I realize that I could do (Import-Csv "file.txt").Attribute1
, but I that would be very impractical do this for every attribute.
These attributes will be different types of variables (some strings, some booleans, some arrays) but I'll go one question at a time.
开发者_开发技巧EDIT :
I don't think it's relevant, but the CSV file came fromGet-ActiveSyncMailboxPolicy -Identity "Policy" | Export-Csv
Soemthing like this?
Import-Csv "file.txt" | foreach-object {
$_.psobject.properties | where-object {
$_.value -eq $true -and $_.name -ne "Attribute4}
精彩评论