我想知道如何针对哈希表或pscustomobject中包含的多个值检查多个值?
仅针对上下文,所使用的cmdlet适用于SharePoint。
到目前为止,这是我的代码:
$usersSearched = [pscustomobject]@{
DisplayName = (@("Administrator";"Service Administrator";"Company
Administrator"))
LoginName = (@("s-1-5-21-2098222698-275879357-2441446288-39577944";"s-1-5-
21-2098222698-275179357-2441446288-39696162";"s-1-5-21-2098262698-275879357-
2441446288-14998143"))
}
#Returns object with one or more values and has a .LoginName property
$result = Get-SPOUser -Site $site | Where-Object {$_.IsSiteAdmin -eq $True}
If ($usersSearched.LoginName -in $result.LoginName)
#Whatever
{
我的问题是我无法让条件恢复真实。 如果有更简单的方法来执行这个看似简单的任务,请告诉我。
答案 0 :(得分:0)
首先,必须使用逗号,而不是分号来分隔数组中的条目:
$usersSearched = [PsCustomObject]@{
DisplayName = @("Administrator","Service Administrator","Company Administrator")
LoginName = @("s-1-5-21-2098222698-275879357-2441446288-39577944",
"s-1-5-21-2098222698-275179357-2441446288-39696162",
"s-1-5-21-2098262698-275879357-2441446288-14998143")
}
其次,您必须使用-contains
代替-in
(或者交换值):
If ($usersSearched.LoginName -contains $result.LoginName)