本文共 1139 字,大约阅读时间需要 3 分钟。
命令:
Get-Mailbox -ResultSize Unlimited | where {$_.SamAccountName -ne $_.Alias}
# 加载 Exchange、AD 模块Import-Module ActivedirectoryAdd-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue# 获取SamAccountName和Alias不相同的邮箱用户$Mailbox = Get-Mailbox -ResultSize Unlimited | where {$_.SamAccountName -ne $_.Alias} | foreach {$_.SamAccountName}# 准备输出集合$GlobalExport = @()# 循环处理邮箱用户foreach ($user in $Mailbox) { $enableuser = Get-aduser -Identity $user | ?{$_.Enable -eq "True"} $Mail = Get-Mailbox -ResultSize Unlimited $enableuser.SamAccountName $Obj = New-Object PSObject $Obj | Add-Member NoteProperty -Name "SamAccountName" -Value $Mail.SamAccountName $Obj | Add-Member NoteProperty -Name "Alias" -Value $Mail.Alias $Obj | Add-Member NoteProperty -Name "PrimarySmtpAddress" -Value $Mail.PrimarySmtpAddress $Obj | Add-Member NoteProperty -Name "UserPrincipalName" -Value $Mail.UserPrincipalName}# 导出输出到CSV$GlobalExport | Export-Csv f:\scripts\Mailbox.csv -Encoding UTF8
转载于:https://blog.51cto.com/zhaodongwei/2066906