Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to get AD account and mailbox information in PowerShell

Shulou Source: shulou.com Published: 2022-06-01 03:45:59 11月11日 Update

Editor to share with you how to get AD account and email information in PowerShell, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.

Sometimes we need to query many attributes of the account, but we need to obtain them through different commands, which are similar to the multi-table join query in SQL Server, such as querying the ad account description, mailbox name, display name, mailbox address, number of mailboxes, mailbox size, archive mailbox size, and number of archive mailboxes of all accounts.

Ad account description-the description information corresponding to the AD account is obtained through Get-adUser

Mailbox name, display name, email address-corresponding to the user's mailbox information, obtained through get-mailbox

Number of mailboxes, mailbox size-corresponding mailbox information, obtained from the command get-mailbox | Get-MailboxStatistics

Archive mailbox size, number of archived mailboxes-corresponding to archived mailbox information, obtained by command get-mailbox-Archive | Get-MailboxStatistics-Archive

These attributes are connected and queried through the common property SamAccountName, as follows:

- -

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 account description-value $Description

$userobject | Add-Member-membertype noteproperty-Name mailbox name-Value $user.Name

$userobject | Add-Member-membertype noteproperty-Name display name-Value $user.DisplayName

$userobject | Add-Member-membertype noteproperty-Name email address-Value $user.PrimarySmtpAddress

$userobject | number of Add-Member-membertype noteproperty-Name mailboxes-Value $userStatistics.ItemCount

$userobject | Add-Member-membertype noteproperty-Name mailbox size-Value $userStatistics.TotalItemSize

$userobject | number of Add-Member-membertype noteproperty-Name archive mailboxes-Value $userarchiveStatistics.ItemCount

$userobject | Add-Member-membertype noteproperty-Name archive mailbox size-Value $userarchiveStatistics.TotalItemSize

$userlist+=$userobject

}

$userlist

$userlist | export-csv-Path c:\ userlist.csv-Encoding utf8-NoTypeInformation

The above is all the contents of the article "how to get AD account and email Information in PowerShell". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Mailboxes accounts archives information size number queries commands addresses properties articles content different not much most more sometimes users knowledge industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Shulou Information Shulou Technology Xiaomi