加載了兩個 JSON 檔案 Get-Content filename.JSON | ConvertFrom-Json
一個物件名稱$SubscriberEmail具有屬性名稱email
第二個物件名稱$ADEnabledUsersEmail 有一個名為Work Email
嘗試比較兩個物件并找到它們,而不是在$ADEnabledUsersEmail物件中并寫出名稱。
這是當前的 foreach 方法,但似乎多次輸出所有電子郵件。
foreach($S in $SubscriberEmail ){
foreach($A in $ADEnabledUsersEmail){
if($A.'Work Email' -eq $S.email ){
Write-Host "User is active"
}else{
Write-Host $s.email
}
}
}
uj5u.com熱心網友回復:
如果你想過濾一個array你可以使用Where-Object或.Where()方法或帶有正確比較運算子的回圈。即:-notin,-notcontains:
$SubscriberEmail.email.where({ $_ -notin $ADEnabledUsersEmail.'Work Email' })
$SubscriberEmail | Where-Object {
$ADEnabledUsersEmail.'Work Email' -notcontains $_.email
}
foreach($email in $SubscriberEmail.email)
{
if($email -notin $ADEnabledUsersEmail.'Work Email')
{
$email
}
}
有更多選項可以過濾arrays,只需在 Google 上搜索過濾陣列 powershell。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/345216.html
標籤:电源外壳
上一篇:嘗試創建計劃任務時出現Powershell錯誤?無法處理引數“Argument”的引數轉換
下一篇:連接檔案夾的輸出
