0

First, i assign this string variable:

PS> $newpath="C:\Program Files (x86)\Intel\iCLS Client"

This works:

PS> [Environment]::SetEnvironmentVariable('Path', $newpath, 'Machine')

This doesn't:

PS> Start-Process Powershell -ArgumentList "-NoExit -noprofile -noninteractive -command [Environment]::SetEnvironmentVariable('Path', $newpath, 'Machine')" -Wait

The second example returns:

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

What am i doing wrong? I'm thinking it has something to do with strings, spaces, or quotes....

thx

johny why
  • 2,047
  • 7
  • 27
  • 52

1 Answers1

0

You are correct. Because your path contains spaces it must be quoted. This should work:

Start-Process Powershell -ArgumentList "-NoExit -noprofile -noninteractive -command [Environment]::SetEnvironmentVariable('Path', '$newpath', 'Machine')" -Wait
Tim Ferrill
  • 1,648
  • 1
  • 12
  • 15