命令:
Get-Mailbox -ResultSize Unlimited | where {$_.SamAccountName -ne $_.Alias}
# 加载 Exchange、AD 模块
Import-Module Activedirectory
Add-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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。