21.3. Exploring Environment Variables

Exploring environment variables is straightforward using the get-childitem cmdlet. To see a complete list of environment variables, use this command from any location:

get-childitem env:*

To sort the environment variables alphabetically and then page the output, use this command:

get-childitem env:* |
sort-object Key |
more

The sort-object cmdlet in the second step of the pipeline sorts the objects passed to it by the first step of the pipeline in ascending alphabetical order by the value of the Key property. Each environment variable is returned as a System.Collections.DictionaryEntry object. That object's Key and Value properties are the most likely to be of interest to you.

Figure 21-9 shows one screen of the environment variables on a Windows XP SP2 machine.

Figure 21.9. Figure 21-9

Alternatively, to display environment variables and navigate to the env drive, use the get-childitem cmdlet:

set-location env:
get-childitem * |
sort-object Key |
more

An alternative form of the second command that produces the same results is:

get-childitem * |
sort-object {$_.Key} |
more

You can display information about the environment variables relating to processors using this command, assuming you are already in the env directory:

get-childitem *process*

Figure 21-10 shows the results of executing the preceding command.

Figure 21.10. Figure 21-10

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.