0

I am running a powershell command from c#, which I call through a webservice

This is the command Set-MailboxAutoReplyConfiguration -identity

Here is my code.

string command = "Set-MailboxAutoReplyConfiguration -identity " + user;

The user I pass through the webservice.

However when I run it I get this error.

System.Management.Automation.RemoteException: The term 'Set-MailboxAutoReplyConfiguration -identity babbey' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I'm not sure where the &#39 is coming from before and after my command. However, if I take out the +user part it works fine. So my problem is the variable that is in the command variable.

1
  • The &#39 is a red herring: it's the error message getting escaped, it's not your input. Could you please post the rest of your code (where you do something interesting with command)? Commented Sep 5, 2012 at 20:27

1 Answer 1

2

If you use PowerShell.AddCommand, you only specify the command name e.g. Set-MailboxAutoReplyConfiguration. Then you call AddParameter on the command to add the parameter e.g.:

var ps = PowerShell.Create();
ps.AddCommand("Set-MailboxAutoReplyConfiguration");
ps.AddParameter("Identity", user);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.