Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何使用Psconsole.psc1-Get-{anything}_Powershell_Batch File - Fatal编程技术网

Powershell 如何使用Psconsole.psc1-Get-{anything}

Powershell 如何使用Psconsole.psc1-Get-{anything},powershell,batch-file,Powershell,Batch File,我使用的Powershell脚本都是这样执行的: PS C:\long\path\to\Psconsole.psc1 -Command {Get-whatever...} 它们都会产生错误: 必须在value'-'运算符的右侧提供一个值表达式。* 下面是一个例子: PS C:\> "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registrat

我使用的Powershell脚本都是这样执行的:

PS C:\long\path\to\Psconsole.psc1  -Command  {Get-whatever...} 
它们都会产生错误:

必须在value'-'运算符的右侧提供一个值表达式。
*

下面是一个例子:

PS  C:\>  "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\psconsole.psc1" -Command "Get-Service"
相同的错误消息:

`You must provide a value expression on the right hand side of the value '-' operator.`
... At line 1...
 - <<< Command "Get-Service"
  + CategoryInfo:         PaserError: (:) [], ParentContainsErrorRecordException
  + FullyQualifiedError:   ExpectedValueExpression
`必须在value'-'运算符的右侧提供一个值表达式`
... 在第1行。。。

-通过将路径括在引号中,可以告诉PowerShell它是一个字符串,然后将-before“-命令”解释为运算符而不是参数

为了避免这种情况,请在您的语句前面加上“Call”operator“&”:


编辑:如果您使用Tab键自动完成路径,当控制台看到完整路径中的空格时,它会自动将&Call操作符放在那里。

该调用操作符修复了错误。谢谢现在,该命令将创建一个powershell窗口。但是,它不执行其中的命令。这可能足以满足我的需要(需要更多的测试),但只是想提醒其他读者。
 & "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\psconsole.psc1" -Command "Get-Service"