![](/img/trans.png)
[英]The term 'Get-CsUser' is not recognized as the name of a cmdlet, function, script file, or operable program
[英]the term is not recognized as the name of a cmdlet, function, script file, or operable program
我正在尝试在我的 C# 程序中运行 Powershell 命令,但出现错误
该术语未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。 检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
我什至在 Powershell 中手动复制了这个完全相同的命令并且它有效。
代码如下
PowerShell ps = PowerShell.Create();
var cmd = "scp -i \"path\\to\\ssh_key\" \"path\\to\\source_file\" root@192.168.x.xxx:/data/user_storage";
ps.AddCommand(cmd);
ps.Invoke();
.AddCommand()
PowerShell SDK 方法接受命令的名称或文件路径,而不是整个命令行。
为了像在交互式 PowerShell 会话中一样执行命令行,请改用.AddScript()
方法。
或者,仅将可执行名称/路径传递给.AddCommand()
并在.AddArgument()
为每个参数调用.AddArgument()
。
请注意,您并不严格需要 PowerShell 来执行带有参数的可执行文件(除非您需要shell功能,例如>
)。
尝试使用具有管理员权限的 cmd 而不是 PowerShell
你的工作可以完成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.