Several methods of Powershell Get Domain mailbox

Source: Internet
Author: User

First,disconnected mailboxes

1,finding disconnected mailboxes

The first function is called Get-disconnectedmailbox and the name are pretty much self explanitory. This function would give you a list of all disconnected mailboxes on each of the your mailbox servers. Take a look at the following code:

functionget-Disconnectedmailbox {[Cmdletbinding ()]param([Parameter (Position=0, mandatory=$false)] [System.String]$Name= ' *')$mailboxes= get-MailboxServer$mailboxes| %{        $disconn= Get-mailboxstatistics-server$_. name |? {$_. Disconnectdate-ne $null }        $disconn| ? {$_. displayname-like $Name} |Select DisplayName,@{n="storemailboxidentity"; e={$_. Mailboxguid}}, Database}}
View Code

Note: If you've recently deleted a mailbox, but it's not showing on when running Get-disconnectedmailbox, you M ay need to force Exchange to recognize this by running the Clean-mailboxdatabase cmdlet.

2,purging disconnected mailboxes

You purge mailboxes using the Remove-mailbox cmdlets, specifying the storemailboxidentity and Database for the disconnected Mailbox in question. For a good example of the, check out Nitin Gupta's post on removing disconnected mailboxes.

In a effort to simplify the purging of disconnected mailboxes, I wrote the Remove-disconnectedmailbox function which is de Signed to work with Get-disconnectedmailbox. Here is the code:

functionremove-Disconnectedmailbox {[Cmdletbinding (supportsshouldprocess=$true)]    param([Parameter (Position=0, Valuefrompipelinebypropertyname=$true, mandatory=$true)] [System.String]$StoreMailboxIdentity, [Parameter (Position=1, Valuefrompipelinebypropertyname=$true, mandatory=$true)] [System.String]$Database        )        Process{Remove-mailbox @Psboundparameters}}
View Code
Get-disconnectedmailbox "Bill Jones" | Remove-disconnectedmailbox-confirm:$false
$_. Storemailboxidentity-database ' db1′-user ' contoso\bboyer '-alias ' Bboyer '}

Reference to Blog

Two

Several methods of Powershell Get Domain mailbox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.