【发布时间】:2020-02-20 09:45:18
【问题描述】:
我需要修改以下脚本,该脚本部分工作。
它基本上是查询Office 365用户、联系人、组和已删除用户,然后将其与用户输入匹配,然后在找到时将其显示在Out-GridView上。
Try {
Install-Module MSOnline -ErrorAction Stop
Import-Module MSOnline -ErrorAction Stop
$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
}
Catch { Write-Warning "Unable to load Microsoft Office 365 module because $($Error[0])"; Exit }
$UPN = Read-Host -Prompt "Please enter the User Principal Name to search (wildcard accepted)"
If ($UPN) {
$UPN = $search
$MSOLActiveUsers = Get-MsolUser -All
$MSOLDeletedUsers = Get-MsolUser -All -ReturnDeletedUsers
$MSOLGroups = Get-MsolGroup -All
$MSOLContacts = Get-MsolContact -All
$MSOLRecipients = Get-Recipient -ResultSize Unlimited
$MSOLCombinedResults = $MSOLActiveUsers + $MSOLDeletedUsers + $MSOLGroups + $MSOLContacts + $MSOLRecipients
$MSOLCombinedResults | Where-Object { $_.emailaddresses -match $search -or $_.emailaddress -match $search -or $_.userprincipalname -eq $search -or $_.proxyaddresses -match $search }
Switch ($MSOLCombinedResults.Count) {
0 { Write-Warning "No user account with a SamAccountName matching '$($UPN)' found!" }
1 { $MSOLCombinedResults }
default { $MSOLCombinedResults | Out-GridView -Title "Please select a user" -OutputMode Single }
}
}
上述脚本的问题是结果总是无意义的长Gridview?
【问题讨论】:
-
你能告诉我们
$MSOLCombinedResults[0]的内容吗?
标签: powershell scripting active-directory office365 windows-scripting