Categories

Variables and the Environment

One of the things I often find myself doing when working on scripts is checking on variables. The cmdlet Get-Variable is useful for this. What I hadn’t realised was that Get-Variable with out any parameters is equivalent to doing Get-ChildItem -Path variable: which gives a quick check on all variables that are defined in your session.

The other area I often poke into is the environment drive. Unfortunately there isn’t a Get-Environment cmdlet.  We can write a simple function to do this for us

 

001
002
003
004
005
006
007

function get-environment {
param ([string]$name = "")
 
 if (!$name){Get-ChildItem -Path env:}
 else{Get-ChildItem -Path env:\$name} 

}

Leave a Reply