Special Folders in Powershell

 

A good start point is the environment variables special powershell drive, aka Env:. However all folders are not available through this mechanism.

You may want to build a hash table to retrieve them all and optionally add a drive to make your code nicer to read. The code is based on the GetNames static method of an enum to retrieve the various names, knowing that the enumeration we are interested in are Environment.SpecialFolder.

So here we go:

<pre class="lang:default decode:true  " title="Retrieving special folders in Powershell">$SpecialFolders = @{}
$names = [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])
foreach($name in $names)
{
  if($path = [Environment]::GetFolderPath($name)){
    $SpecialFolders[$name] = $path
    # New-PSDrive -Name $name -PSProvider FileSystem -Root $path
  }
}