/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Create System Variable From MSH "," Setting the Path / system variables from MSH "," 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. "," ")

Thursday, November 03, 2005

 


Create System Variable From MSH (Part2)



I had some problems creating Sytem-wide environment variables :

Setting the Path / system variables from MSH
I found a workaround, Create System Variable From MSH

but also I got some Excelent answers from the NG (both better) :

One from Keith Hill :

Take a look at .NET's System.Environment.SetEnvironmentVariable() methods.
One of the overloads takes an enum that lets you specify User or System
environment variable.
--
Keith


I did And yes :
this Works :

[System.Environment]::SetEnvironmentVariable("NewSysVar","Val",[System.EnvironmentVariableTarget]"Machine")
and a tip from Jeffrey Snover :

MSH> $env = (new-object -com "WScript.Shell").Environment("SYSTEM")
MSH> ,$env gm
TypeName: System.__ComObject#{f935dc29-1cf0-11d0-adb9-00c04fd58a0b}
Notice the leading ",". The problem that you had was the $env is ENUMERABLE
so putting it into the pipeline unrolls it into its parts (strings), By
putting a "," in front you are creating a LIST of 2 elements
1) $NULL
2) $ENV (the IENUMERABLE)
This list gets unrolled and passes on its parts ($ENV) so that GM reports
correctly.
The less esoteric way to address this is:
MSH> gm -input $env
In any case, the Setter works:
MSH> $env.item("TMP") = "c:\temp"



,$env.count()

and this one really got me, that little comma solves alot of the problems I was having exploring .NET collections etc. from MSH.

E.g. the problem I had while working with The DataTable :
see Strange behavour of get-member on DataTables

I will blog more about this later I think, but for now this works :

$dt = new-object system.data.dataTable
,$dt gm

thx Both.

gr /\/\o\/\/


Comments:
Blogger Sung Meister
thanks to yourhelp, now i get to see the difference between "ls env: | gm" and ",(ls env:) | gm".

I still think this is a lil' bit funky of a syntax that we have to use "," to retrieve the value of collection type...
 
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?