Powershell Get Domain Mailbox的几种方法

一、Disconnected Mailboxes

1、Finding Disconnected Mailboxes

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

function Get-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 up when running Get-DisconnectedMailbox, you may need to force Exchange to recognize this by running the Clean-MailboxDatabase cmdlet.


 

2、Purging Disconnected Mailboxes

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

In an effort to simplify the purging of disconnected mailboxes, I wrote the Remove-DisconnectedMailbox function that is designed to work with Get-DisconnectedMailbox. Here is the code:

function Remove-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
Get-DisconnectedMailbox “Bradford Boyer” | %{Connect-Mailbox -Identity $_.StoreMailboxIdentity -Database ‘DB1′ -User ‘contoso\bboyer’ -Alias ‘bboyer’}

参考至博文<http://www.mikepfeiffer.net/2010/06/managing-disconnected-exchange-mailboxes-with-powershell/>


 

二、

转载于:https://www.cnblogs.com/thescentedpath/p/psexmailbox.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值