You want to access common system
variables such as ‘%appdata%’ or
‘%windir%’ just like in Explorer for
personalized scripts created with
Windows PowerShell.
In PowerShell, you can easily
access all system variables and use
them in scripts. The scripts thus become
more independent from the actual
installation and can be transferred to
another computer easily. Moreover, you
can also request and use particular
system information such as processor
specifications.
The environment variables are present
in the ‘Env:’ section of PowerShell. You
will thus get a complete list of all the
existing system variables with their
respective values with the command
get-childitem env:. Individual values
out of these can be referred to in the
form ‘$env:windir’ so that access via the
prefixed drive specification is possible
even from other locations.
You can get to know the methods and
properties available for such an object
with the command
get-childitem
env: | get-member. However to list
the actual properties of a particular
entry, use the command ‘
get-item
env:windir | format-list –
property*. This command loads the
‘windir’ variable as object and transfers
it to the command after the pipe icon for
list release of all properties.
Use the command let ‘
rename-item’
in the form rename-item env:tmp
–newname tmp2 to rename an
environment variable. You can also
easily change the content with the help
of ‘Set-item’ and the parameter ‘-value’.
For example, redefine the temporary
folder with ‘set-item env:TMP –value ‘C:\Daten\Temp’’. The functions can thus be
combined. Read out the path variable in
the system and add it to the folder ‘C:\
Test’ using ‘set-item env:path -value (getcontent
env:path+’;C:\Test’).
ATTENTION: Changes to the environment
variables are applicable only for the
current session. Permanent settings
need to be configured in the profile of
PowerShell or in the system. However
you can still change or rename the predefined
system variables if you know the
exact effect of your action.