#PSTip Get the fully qualified path of the system directory

There are many ways to get the path of the system directory (e.g system32). Here’ one that I find very useful that involves the .NET Environment class:

PS> [System.Environment]::SystemDirectory
C:\WINDOWS\system32

I use it in my PowerShell profile and adds it to my session’s Env drive so I can conveniently query its value  just as I query all environment variables:

# add a new environment variable
PS> $env:SystemDirectory = [Environment]::SystemDirectory

# query it using the $env drive variable
PS> $env:SystemDirectory
C:\WINDOWS\system32

Which also makes it very easy to be embedded and expanded in a string:

PS> "The path of the system directory is: $env:SystemDirectory"
The path of the system directory is: C:\WINDOWS\system32
Share on: