-----提供AD\Exchange\Lync\Sharepoint\CRM\SC\O365等微软产品实施及外包,QQ:185426445.电话18666943750
有时候我们需要查询账号的很多属性,但是需要通过不同的命令去获取,有点类似SQL Server里面的多表连接查询,比如查询所有账号的ad账号描述,邮箱名,显示名,邮箱地址,邮箱数目,邮箱大小,存档邮箱大小,存档邮箱数目。
ad账号描述---对应AD账号的描述信息,通过Get-adUser 获取
邮箱名,显示名,邮箱地址---对应用户邮箱信息,通过get-mailbox获取
邮箱数目,邮箱大小---对应邮箱信息,通过命令get-mailbox |Get-MailboxStatistics 获取
存档邮箱大小,存档邮箱数目---对应存档邮箱信息,通过命令get-mailbox -Archive|Get-MailboxStatistics -Archive获取
这些属性通过SamAccountName这个共同的属性连接和查询,具体操作如下:
--------------------------------------------------------------------------------------------------------------------------------------------------
cls
Add-PSSnapin microsoft.exchange*
$mbxinfo=Get-mailbox -ResultSize unlimited |%{$_.SamAccountName}
$userlist = @()
foreach ($i in $mbxinfo)
{
$Description=Get-adUser $i -Properties * |%{$_.Description}
$user=get-mailbox $i
$userStatistics=get-mailbox $i |Get-MailboxStatistics
$userarchiveStatistics=get-mailbox $i -Archive|Get-MailboxStatistics -Archive
$userobject=New-object psobject
$userobject | Add-Member -membertype noteproperty -Name AD账号描述 -value $Description
$userobject | Add-Member -membertype noteproperty -Name 邮箱名 -Value $user.Name
$userobject | Add-Member -membertype noteproperty -Name 显示名 -Value $user.DisplayName
$userobject | Add-Member -membertype noteproperty -Name 邮箱地址 -Value $user.PrimarySmtpAddress
$userobject | Add-Member -membertype noteproperty -Name 邮箱数目 -Value $userStatistics.ItemCount
$userobject | Add-Member -membertype noteproperty -Name 邮箱大小 -Value $userStatistics.TotalItemSize
$userobject | Add-Member -membertype noteproperty -Name 存档邮箱数目 -Value $userarchiveStatistics.ItemCount
$userobject | Add-Member -membertype noteproperty -Name 存档邮箱大小 -Value $userarchiveStatistics.TotalItemSize
$userlist+=$userobject
}
$userlist
$userlist|export-csv -Path c:\userlist.csv -Encoding utf8 -NoTypeInformation