列出转发给特定用户的所有邮箱

时间:2014-02-20 17:55:56

标签: powershell exchange-server

我有这个脚本列出了转发电子邮件的所有邮箱,但是,我很好奇是否有办法让它返回转发给特定用户的所有邮箱。基本上我试图找出每个邮箱转发邮件到“johndoe”。任何帮助将不胜感激!这是交换2007年btw ...

到目前为止,这是脚本:

  

$ fwds = get-mailbox | Where-Object {$ _ .ForwardingAddress -ne $ null}   |选择名称,转发地址

     

foreach($ fwd in $ fwds){$ fwd | add-member -membertype noteproperty   -name“ContactAddress”-value(get-contact $ fwd.ForwardingAddress).WindowsEmailAddress}

     

$ FWD的

2 个答案:

答案 0 :(得分:0)

Exchange使用CanonicalName作为转发地址,因此您需要从用户名中查找。由于它可能是邮箱,DL或联系人,我所知道的最简单的方法是使用Get-Recipient,并获取Identity属性。

$RecipientCN = (get-recipient johndoe).Identity
get-mailbox | Where-Object { $_.ForwardingAddress -eq $RecipientCN }

答案 1 :(得分:0)

@ mjolinor的版本有效,但速度很慢,因为它加载了所有邮箱。在我的系统上,大约需要30秒才能完成约300个邮箱。

通过在Get-Mailbox命令中添加一个过滤器,只返回实际转发的过滤器,可以加快速度,如下所示:

$RecipientCN = (get-recipient johndoe).Identity
Get-Mailbox -ResultSize Unlimited -Filter {ForwardingAddress -ne $null} | Where-Object {$_.ForwardingAddress -eq $RecipientCN}

但是等等,我们可以变得更快!为什么不在过滤器中搜索正确的用户权限?可能是因为很难正确理解语法,因为在-Filter中使用变量会让人感到困惑。

诀窍是在整个过滤器表达式周围使用双引号,并在变量周围使用单引号:

$RecipientCN = (get-recipient johndoe).Identity
Get-Mailbox -ResultSize Unlimited -Filter "ForwardingAddress -eq '$RecipientCN'"

此版本在0.6秒内返回相同的结果 - 约快50倍