2015-09-14 18 views
1

我試圖通過我的C#應用​​程序從用戶帳戶中只刪除SIP地址。我可以使用以下命令通過Exchange管理外殼成功刪除它。通過交換機從用戶中刪除SIP地址

Set-Mailbox "identity" -EmailAddresses @{Remove="sip: [email protected]"} 

在我的C#應用​​程序我有以下的,但我不知道如何讓「@ {刪除=」 SIP:[email protected]「}」在那裏。

string termUserEmail = txtboxTermFirstName + "." + txtboxTermLastName + "@domain.com"; 

PSCommand command1 = new PSCommand(); 
command1.AddCommand("Set-Mailbox"); 
command1.AddParameter("Identity", termUserEmail); 

var sipAddress = new Hashtable(); 

sipAddress.Add("remove", termUserEmail); 
command1.AddParameter("EmailAddresses", sipAddress); 

所以,我不知道如何讓這個東西正確執行命令。我確實看過C# - Remove Exchange Email Address via Powershell Runspace這是我至今的事。

回答

0

經過多次拉動我有這件事。我錯誤地認爲我需要雙引號。當我發佈ps命令時,它會爲我提供我不知道的引號。所以基本上這是一個簡單的修復。

//刪除SIP地址

 string idTermEmail = "sip:" + txtTermFirstName.Text + "." + txtTermLastName.Text + "@domain.com"; 


     PSCommand command3 = new PSCommand(); 
     command3.AddCommand("Set-Mailbox"); 
     command3.AddParameter("Identity", username); 

     var sipAddress = new Hashtable();    

     sipAddress.Add("remove", idTermEmail); 
     command3.AddParameter("EmailAddresses", sipAddress); 

     powershell.Commands = command3; 
     powershell.Invoke(); 

WAM巴姆謝謝大娘全部完成。我希望別人能夠利用這一點;)