1

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.

Community
  • 1
  • 1
Advancin
  • 171
  • 1
  • 2
  • 12

1 Answers1

0

After much hair pulling I've got this thing going. I was mistaken in thinking that I needed the double quotes. When I was issuing the ps commands it was putting the quotes for me which I didn't know. So basically it was a simple fix.

//remove sip address

        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 thank you ma'am all done. I hope others get some use out of this ;)

Advancin
  • 171
  • 1
  • 2
  • 12