/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Obfuscated Monad Script "," Get Binary SID in MSH (Share Security Update) "," Replace Security on existing share using MSH "," Einstein "," Runas with loading Profile script in MSH "," do the MSH - CMD- MSH loop. & RunAs in MSH "," list processes of remote computer from MSH "," MSH Error message line number and Trap. "," Strange behavour of get-member on DataTables "," CodeSigning in Monad" Shell Beta 2 (for .NET Frame... "," ")

Wednesday, November 02, 2005

 


Setting the Path / system variables from MSH



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\/\/


Comments: Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?