twitter

Posting tweet...

Using standard windows environment variables in PowerShell

The default Windows environment variables acts like a drive within powershell.  You can poll the available Windows environment variables just like you were getting the contents of a drive or folder.  Open a PowerShell console and run the following:

1
2
Set-location env:\
get-childitem

This will return all of the local environment variables, similar to the following:

 
Name                           Value
----                           -----
Path                           C:\Program Files\PHP\;C:\Program Files\Support Tools\;C:\WINDOWS\system32;C:\WINDOWS;...
TEMP                           C:\DOCUME~1\admini\LOCALS~1\Temp\1
SESSIONNAME                    RDP-Tcp#1
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
USERDOMAIN                     HOME
PROCESSOR_ARCHITECTURE         x86
SystemDrive                    C:
APPDATA                        C:\Documents and Settings\admini\Application Data
windir                         C:\WINDOWS
ALLUSERSPROFILE                C:\Documents and Settings\All Users
TMP                            C:\DOCUME~1\admini\LOCALS~1\Temp\1
USERDNSDOMAIN                  HOME.COM
USERPROFILE                    C:\Documents and Settings\admini
ProgramFiles                   C:\Program Files
FP_NO_HOST_CHECK               NO
HOMEPATH                       \Documents and Settings\admini
COMPUTERNAME                   SERVER2
USERNAME                       admini
NUMBER_OF_PROCESSORS           2
PROCESSOR_IDENTIFIER           x86 Family 6 Model 8 Stepping 6, GenuineIntel
ClusterLog                     C:\WINDOWS\Cluster\cluster.log
SystemRoot                     C:\WINDOWS
ComSpec                        C:\WINDOWS\system32\cmd.exe
LOGONSERVER                    \\SERVER2
CommonProgramFiles             C:\Program Files\Common Files
PROCESSOR_LEVEL                6
PROCESSOR_REVISION             0806
CLIENTNAME                     LVSUP900
PHPRC                          C:\Program Files\PHP\
OS                             Windows_NT
HOMEDRIVE                      C:

You can take advantage of these variables by setting the desired environment variable to a PowerShell variable and then using it in your script.  Here is an example of pulling the local computer name and setting it to a variable in PowerShell:

1
2
PS $computername = get-content env:computername
PS $computername
SERVER2
  • Twitter
  • Facebook
  • LinkedIn
  • Digg
  • Google Bookmarks
  • Slashdot
  • StumbleUpon
  • Live
  • FriendFeed
  • Ping.fm
  • Print
  • email
  • PDF
  • RSS

1 comment to Using standard windows environment variables in PowerShell

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">