Remove a SIP address from user via exchange

时间:2015-09-14 16:17:19

标签: c# powershell exchange-server

I'm trying to remove only the SIP address from a user account via my C# application. I can successfully remove it via the exchange management shell with the following command.

Set-Mailbox "identity" -EmailAddresses @{Remove="sip: firstname.lastname@domain.com"}

In my c# app I've got the following but I'm not sure how to get the "@{Remove="sip:firstname.lastname@domain.com"}" in there.

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);

So, I'm not sure how to get this thing to execute the command correctly. I did look at C# - Remove Exchange Email Address via Powershell Runspace which gt me this far.

1 个答案:

答案 0 :(得分: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 bam谢谢你,我已经完成了。我希望其他人可以使用它;)