首先,我分配这个字符串变量:
PS> $newpath="C:\Program Files (x86)\Intel\iCLS Client"
这有效:
PS> [Environment]::SetEnvironmentVariable('Path', $newpath, 'Machine')
这不会:
PS> Start-Process Powershell -ArgumentList "-NoExit -noprofile -noninteractive -command [Environment]::SetEnvironmentVariable('Path', $newpath, 'Machine')" -Wait
第二个示例返回:
At line:1 char:46
+ [Environment]::SetEnvironmentVariable('Path', C:\Program Files (x86)\Intel\iCLS ...
+ ~
Missing expression after ','.
At line:1 char:47
+ [Environment]::SetEnvironmentVariable('Path', C:\Program Files (x86)\Intel\iCLS ...
+ ~~~~~~~~~~
Unexpected token 'C:\Program' in expression or statement.
At line:1 char:98
+ ... ient, 'Machine')
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterToken
我究竟做错了什么?我认为它与字符串、空格或引号有关....
谢谢