This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
Setting the Path from MSH,
as Path is an internal CMD command, the path command will not work in MSH
No Problem you would think, I do it like this :
$env:path = $env:path + ";c:\mytest"
but if you then close MSH and start it again its gone because te variable is set only for the current session.
I did remember the good old Wscript.shell trick for this :
( Exually, it was the other way around, I used this as an answer to a NG post, and wanted to look how MSH would handle this(setting system Variables), as I had some issues with this before. that's where that path adventure started ;-))Set WshShell = WScript.CreateObject("WScript.Shell")
Set Env = WshShell.Environment("SYSTEM")
Env("Path") = Env("Path") & ";c:\mytest"
(you can also use User, Volatile, or Process as scope here)
so, no problem
$env = (new-object -com "WScript.Shell").Environment("SYSTEM")
but :
MSH > $env = (new-object -com "WScript.Shell").Environment("SYSTEM")
MSH> $env gm
TypeName: System.String
Oops I get a string back, so I can not set it from MSH.
Ok then use WMI :
$env = get-WMIObject win32_environment -filter "Name = 'Path'"MSH
$env.VariableValue = $env.VariableValue + ";c:\test"
Yes, this Works, at least I don't have to do the Registry trick :
( setting HKLM\System\CurrentControlSet\Control\Sessionmanager\Environment)
but this gets not updated while running.
only problem here is I don't have a create method in the WMI class.
gr /\/\o\/\/