Powershell管理系列(二十五)PowerShell操作之获取AD账号及邮箱信息
-----提供AD\Exchange\Lync\Sharepoint\CRM\SC\O365等微軟產(chǎn)品實(shí)施及外包,QQ:185426445.電話(huà)18666943750
有時(shí)候我們需要查詢(xún)賬號(hào)的很多屬性,但是需要通過(guò)不同的命令去獲取,有點(diǎn)類(lèi)似SQL Server里面的多表連接查詢(xún),比如查詢(xún)所有賬號(hào)的ad賬號(hào)描述,郵箱名,顯示名,郵箱地址,郵箱數(shù)目,郵箱大小,存檔郵箱大小,存檔郵箱數(shù)目。
ad賬號(hào)描述---對(duì)應(yīng)AD賬號(hào)的描述信息,通過(guò)Get-adUser 獲取
郵箱名,顯示名,郵箱地址---對(duì)應(yīng)用戶(hù)郵箱信息,通過(guò)get-mailbox獲取
郵箱數(shù)目,郵箱大小---對(duì)應(yīng)郵箱信息,通過(guò)命令get-mailbox |Get-MailboxStatistics 獲取
存檔郵箱大小,存檔郵箱數(shù)目---對(duì)應(yīng)存檔郵箱信息,通過(guò)命令get-mailbox -Archive|Get-MailboxStatistics -Archive獲取
這些屬性通過(guò)SamAccountName這個(gè)共同的屬性連接和查詢(xún),具體操作如下:
--------------------------------------------------------------------------------------------------------------------------------------------------
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賬號(hào)描述 ? ? ?-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 郵箱數(shù)目 ? ? ? ?-Value $userStatistics.ItemCount
$userobject | Add-Member -membertype noteproperty -Name 郵箱大小 ? ? ? ?-Value $userStatistics.TotalItemSize
$userobject | Add-Member -membertype noteproperty -Name 存檔郵箱數(shù)目 ? ?-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
總結(jié)
以上是生活随笔為你收集整理的Powershell管理系列(二十五)PowerShell操作之获取AD账号及邮箱信息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: hdu 5563 Clarke and
- 下一篇: 在Java中定义常量