从c#webservice运行powershell命令
我正在从c#运行powershell命令,我通过Web服务调用它 这是命令从c#webservice运行powershell命令,c#,powershell,C#,Powershell,我正在从c#运行powershell命令,我通过Web服务调用它 这是命令Set-MailboxAutoReplyConfiguration-identity 这是我的密码 string command = "Set-MailboxAutoReplyConfiguration -identity " + user; 我通过Web服务传递的用户 然而,当我运行它时,我得到了这个错误 System.Management.Automation.RemoteException:术语&39;设置Mail
Set-MailboxAutoReplyConfiguration-identity
这是我的密码
string command = "Set-MailboxAutoReplyConfiguration -identity " + user;
我通过Web服务传递的用户
然而,当我运行它时,我得到了这个错误
System.Management.Automation.RemoteException:术语&39;设置MailboxAutoReplyConfiguration-identity babbey';无法识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
我不确定'在我的命令之前和之后是从哪里来的。但是,如果我取出+用户部分,它就可以正常工作。因此,我的问题是命令变量中的变量。如果使用
PowerShell.AddCommand
,则只指定命令名,例如Set-MailboxAutoReplyConfiguration
。然后在命令中调用AddParameter以添加参数,例如:
var ps = PowerShell.Create();
ps.AddCommand("Set-MailboxAutoReplyConfiguration");
ps.AddParameter("Identity", user);
'是一个转移视线的问题:这是转义的错误消息,不是您的输入。你能把剩下的代码贴出来吗(在那里你用命令做了一些有趣的事情)?