Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3979560
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:11:06+00:00 2026-05-20T05:11:06+00:00

I wrote a very small application, which access the Remote Power Shell of Exchanger

  • 0

I wrote a very small application, which access the Remote Power Shell of Exchanger Server 2010 SP1 and execute some scripts. Here is the sample code. Everything is in try and catch block.

  string insecurePassword = "mypassword";
  SecureString securePassword = new SecureString();
  foreach (char passChar in insecurePassword.ToCharArray())
  {
   securePassword.AppendChar(passChar);
  }
  PSCredential credential = new PSCredential("mydomain\\administrator", securePassword);

  WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://exchange2010.domain.com/powershell?serializationLevel=Full"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
  connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
  Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
  PowerShell powershell = PowerShell.Create();
  PSCommand command = new PSCommand();
  ICollection<System.Management.Automation.PSObject> results;


//The command I want to execute is Set-MailContact with some parameters.



    command.AddCommand("Set-MailContact");
    command.AddParameter("Identity", "SomeIdentityOfContact");
    command.AddParameter("EmailAddressPolicyEnabled", false);
    command.AddParameter("PrimarySmtpAddress", "myEmailAddress@domain.com");
    command.AddParameter("Confirm", false);
    command.AddParameter("Force", true);
    powershell.Commands = command;

    // open the remote runspace
    runspace.Open();
    // associate the runspace with powershell
    powershell.Runspace = runspace;
    // invoke the powershell to obtain the results
    results = powershell.Invoke();

I am trying to set PrimarySmtpAddress of a MailContact, but for some reasons I am getting the following exception:

System.Management.Automation.RemoteException: Cannot process argument transformation on parameter ‘PrimarySmtpAddress’. Cannot convert value “SMTP:myEmailAddress@domain.com” to type “Microsoft.Exchange.Data.SmtpAddress”

I think its must be due to serialization/de-serialization. Does someone have any idea on how to correctly pass the email address’s value?

Any hint help will be highly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:11:07+00:00Added an answer on May 20, 2026 at 5:11 am

    Try leaving off the SMTP: qualifier. That’s already implicit in the -primarySMTPAddress parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to C#. My boss asked me to wrote some code using
I am experiencing some very odd timing behavior from a function I wrote. If
I'm VERY new to Linq. I have an application I wrote that is in
I have an application running in IIS which connects to a SQL Server 2008
We have some code that must access low level windows XP os calls which
I want to write a very small Django application in a single file, requiring
I am writing this small code which is part of my Django application. It
For a small to-be-embedded application, I wrote a few functions + struct that work
I wrote a very simple mysql line for my very simple search bar that
I wrote this very simple macro to delete all rows when Column P has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.