开发者

PowerShell: How to evaluate each attribute in an object?

开发者 https://www.devze.com 2023-03-05 09:03 出处:网络
This can be applied to many different scenarios, but specifically I am running: Import-Csv \"file.txt\" | foreach { $_ }

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 from

Get-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}
0

精彩评论

暂无评论...
验证码 换一张
取 消