Finding the Windows Special Folders using PowerShell

In a recent script I wanted to find out the path to one of the special folders in Windows. Special folders are system folders like “Windows”, “System”, “Desktop”, “MyDocuments” and so on.

Well that’s pretty easy, you can simply use the following line:

[Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])

And from the output you’ll see what SpecialFolders are on your system.

SpecialFolders

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now this is nice but it doesn’t show you where these SpecialFolders are, it just shows the name of them. So try this instead.
$SpecialFolders = @{}
$names = [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])

foreach($name in $names | sort Name)
{
if($path = [Environment]::GetFolderPath($name))
{
$SpecialFolders[$name] = $path
}
}

 

Now you’ll get a path as well 🙂

SpecialFolders2

 

 

 

 

 
Comments

No comments yet.

Leave a Reply