2011-11-01 32 views
0

我想檢查組織中所有郵箱的屬性;如果該值爲null,則我想補充一個屬性(電子郵件地址)檢查郵箱屬性並添加值如果爲空

get-mailbox -Organization test.me.net | 
if (-ForwardingSmtpAddress -eq {}) 
{ 
Set-Mailbox -DeliverToMailboxAndForward $true -ForwardingSmtpAddress [email protected] 
} 

我收到錯誤消息是...

術語「如果」沒有公認的名稱cmdlet,函數,腳本文件或可操作的程序。檢查名稱的拼寫 ,或者如果包含路徑,請驗證路徑是否正確,然後重試。 在C:\腳本\ smtpaddress.ps1:2炭:3 +如果< < < <(-ForwardingSmtpAddress -eq {}) + CategoryInfo:ObjectNotFound:(如果:字符串)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException

任何想法如何解決這個問題?

感謝您的閱讀,科爾姆

回答

0

使用Filter參數來獲取沒有在ForwardingSmtpAddress屬性值的郵箱,管重轉到Ste-Mailbox並設置DeliverToMailboxAndForward和ForwardingSmtpAddress參數。請記住,所有郵箱將郵件轉發到管理員信箱:

Get-Mailbox -ResultSize Unlimited -OrganizationalUnit me.net/test -Filter {ForwardingSmtpAddress -eq $null} | Set-Mailbox -DeliverToMailboxAndForward $true -ForwardingSmtpAddress [email protected] 
+0

非常感謝謝伊 只是一個錯字與a)而不是};很棒! :) –

+0

謝謝,修正了錯字。 –

0

你可以,如果你把它管,如果每做一個一個的for-each是這樣的:

get-mailbox | % { 
if ($_.ForwardingSmtpAddress -eq {}) 
{ 
*Do something* 
} 
} 

但你應該只使用一個過濾器和管道結果爲一組的郵箱命令(問號代表位置對象):

get-mailbox | ? {$_.ForwardingSMTPAddress -eq {}} | Set-Mailbox...... 
0

我對能夠保留策略對於那些誰申請沒有寫一個腳本。

Get-Mailbox -filter {retentionpolicy -eq $null} | Set-Mailbox -retentionpolicy "120DayRetention Policy"

工作就像一個魅力。

相關問題