PowerShell:如何评估对象中的每个属性?
这可以应用于许多不同的场景,但具体来说,我正在运行:
Import-Csv "file.txt" | foreach { $_ }
一般来说,输出是:
Attribute1 : $true
Attribute2 : asdf
Attribute3 : {}
Attribute4 : $true
如何运行 foreach 循环来比较每个属性的名称和值? 例如,请参阅哪个属性等于 $true 但不是 Attribute4。 (我愿意使用 foreach 以外的东西,这就是我所知道的。)
我意识到我可以做 (Import-Csv "file.txt").Attribute1
,但我认为对每个属性都这样做是非常不切实际的。
这些属性将是不同类型的变量(一些字符串、一些布尔值、一些数组),但我将一次只回答一个问题。
编辑:
我认为这不相关,但 CSV 文件来自Get-ActiveSyncMailboxPolicy -Identity“策略”|导出-CSV
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有这样的事吗?
Soemthing like this?