我向 Office365 查询了与Chris的 displayName 匹配的所有用户的列表。
我想提示用户他们想要选择哪个 Chris。在这样做时,我有以下 for..each 代码
$tmpUserOffice = Get-MsolUser -SearchString "*Chris*"
if ($tmpUserOffice -is [array])
{
if ($tmpUserOffice.Count -lt 50) {
Write-Host "Many matching users in MSOL. Choose which one you want to save"
for ($i = 0; $i -lt $tmpUserOffice.Count; $i++) {
Write-Host $i " " $($tmpUserOffice[$i].DisplayName)
}
Write-Host $tmpUserOffice.Count " None of the above"
$chosen = Read-Host
if ($chosen -eq $tmpUserOffice.Count) {
Write-Warning "Nothing found. Try searching with different criteria or use wildcards"
Write-Output $null
}
Write-Host $tmpUserOffice[$chosen] " selected"
$tmpUserOffice = $tmpUserOffice[$chosen]
exit
}
else {
Write-Warning "More than 50 matches found. Try searching for more specific criteria"
}
}
我的问题之一是如何完成以下行的内容
Write-Host $i " " $($tmpUserOffice[$i].DisplayName)
目前的输出是
Many matching users in MSOL. Choose which one you want to save
0
1
2 None of the above
我需要进行哪些更改以确保该值实际写入值?
编者注:问题结果与此处发布的代码无关,原则上确实有效。