简体   繁体   English

该术语未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

[英]the term is not recognized as the name of a cmdlet, function, script file, or operable program

I am trying to run a Powershell command in my C# program but I get the error我正在尝试在我的 C# 程序中运行 Powershell 命令,但出现错误

the term is not recognized as the name of a cmdlet, function, script file, or operable program.该术语未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again.检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。

I even copied this same exact command in Powershell manually and it worked.我什至在 Powershell 中手动复制了这个完全相同的命令并且它有效。

The code follows as代码如下

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();

The .AddCommand() PowerShell SDK method accepts the name or file path of a command, not an entire command line . .AddCommand() PowerShell SDK 方法接受命令的名称文件路径,而不是整个命令行

In order to execute a command line as you would in an interactive PowerShell session, use the .AddScript() method instead.为了像在交互式 PowerShell 会话中一样执行命令行,请改用.AddScript()方法。

Alternatively, pass only the executable name/path to .AddCommand() and follow it with an .AddArgument() call for each argument.或者,仅将可执行名称/路径传递给.AddCommand()并在.AddArgument()为每个参数调用.AddArgument()

Note that you don't strictly need PowerShell in order to execute an executable with arguments (unless you need shell features such as > ).请注意,您并不严格需要 PowerShell 来执行带有参数的可执行文件(除非您需要shell功能,例如> )。

Try to use cmd with Administrator rights instead of PowerShell尝试使用具有管理员权限的 cmd 而不是 PowerShell

your work can be done你的工作可以完成

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 术语“ Get-CsUser”不能识别为cmdlet,函数,脚本文件或可运行程序的名称 - The term 'Get-CsUser' is not recognized as the name of a cmdlet, function, script file, or operable program 术语“添加编号”不被视为cmdlet,函数,脚本文件或可运行程序的名称 - The term 'Add-Number' is not recognized as the name of a cmdlet, function, script file, or operable program 无法将“ Invoke-Sqlcmd”识别为cmdlet,函数,脚本文件或可运行程序的名称 - 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program 术语“Add-AzureAccount”未被识别为cmdlet,函数,脚本文件的名称 - The term 'Add-AzureAccount' is not recognized as the name of a cmdlet, function, script file 术语''不被识别为cmdlet的名称, - The term ' ' is not recognized as the name of a cmdlet, 术语“ New-CsOnlineSession”不被视为cmdlet的名称 - The term 'New-CsOnlineSession' is not recognized as the name of a cmdlet 术语“Connect-AzureAD”未被识别为 cmdlet 的名称 - The term 'Connect-AzureAD' is not recognized as the name of a cmdlet 术语“add-migration”未被识别为 cmdlet 的名称 - The term 'add-migration' is not recognized as the name of a cmdlet 在C#函数中,术语'connect-QADService'不被识别为cmdlet的名称。 - The term 'connect-QADService' is not recognized as the name of a cmdlet… inside C# function “'add-migration' 一词未被识别为 cmdlet 的名称”Visual Studio 2019 - “the term 'add-migration' is not recognized as the name of a cmdlet” visual studio 2019
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM