Powershell 术语'';未识别为cmdlet的名称

Powershell 术语'';未识别为cmdlet的名称,powershell,powershell-2.0,Powershell,Powershell 2.0,我尝试使用“run”命令在一行中运行此命令: 但我得到了这个错误: GigaBytes : The term 'GigaBytes' 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 t

我尝试使用“run”命令在一行中运行此命令:

但我得到了这个错误:

GigaBytes : The term 'GigaBytes' 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.
At line:1 char:137
+ ... t Name, @{Name=GigaBytes;Expression={$_.Length / 1GB}}
+                    ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (GigaBytes:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
该代码在启动的Powershell窗口上工作,而不使用
Powershell-NoExit


有什么办法可以解决吗?

由于命令行参数通过“Run”进行标记的方式,您需要对
GigaBytes
左右的双引号进行转义(使用
\
转义字符),或者用单引号代替它们。这两个
Select Object
命令中的任何一个都应起作用:

Select-Object Name, @{Name=\"GigaBytes\";Expression={$_.Length / 1GB}}

这是因为任何用双引号括起来的东西都将被解释为单个参数


有关如何通过“运行”标记命令行参数的更详细说明,请参见答案。

刚刚尝试过,没有出现任何此类错误。@Rahul我是说,开始->运行“粘贴代码”,但我得到了错误。。。你试过同样的步骤吗?那样你很可能会出错。而是开始->运行->powershell。一旦贝壳窗打开。。粘贴coe并运行。会的fine@Rahul我需要在运行中更改主机名,这涉及到另一个软件,这就是我为什么这么看的原因。我想相信有一些东西可以让它按照我的需要工作:(谢谢,最后我发现了pass参数,但这是完全有帮助的。
Select-Object Name, @{Name=\"GigaBytes\";Expression={$_.Length / 1GB}}
Select-Object Name, @{Name='GigaBytes';Expression={$_.Length / 1GB}}