Reputation: 4355
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 ' 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.
Upvotes: 0
Views: 634
Reputation: 202012
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);
Upvotes: 2