1
所以我一直在PowerShell中的以下屬性的對象(這是隻包含一個項目JSON表示):篩選對象的複雜陣列優雅的方式
"NetworkResourcePermittedUsers": [
{
"PermittedUser": {
"UserName": "somedomain\\someuser"
},
"SecurityAccessLevel": {
"Level": "Read"
},
"SecurityAccessMode": {
"Mode": "Allow"
}
}
]
我想要做的是過濾我NetworkResourcePermittedUsers
陣列基於內部SecurityAccessLevel
的Level
場,所以基本上:SecurityAccessLevel.Level
在LINQ我會做這樣的事情:
networkResourcePermittedUsers.Any(x => x.SecurityAccessLevel.Level.Equals("myvalue"))
我知道,在PowerShell中,我可以使用類似:
$networkResourcePermittedUsers -contains "value"
但在這種情況下,-contains
參數假設我有值對象(string
,int
等)
因此所組成的陣列有沒有辦法使用-contains
參數來過濾複雜的對象圖?
類似:
#this is bad code -- doesn't work
$networkResourcePermittedUsers -contains "myvalue" -path SecurityAccessLevel.Level