Skip to content

Instantly share code, notes, and snippets.

@auberginehill
Last active October 9, 2023 00:11
Show Gist options
  • Save auberginehill/9c2f26146a0c9d3d1f30ef0395b6e6f5 to your computer and use it in GitHub Desktop.
Save auberginehill/9c2f26146a0c9d3d1f30ef0395b6e6f5 to your computer and use it in GitHub Desktop.
Retrieves Special Folders' names and corresponding paths along with the environment variable values in Windows PowerShell, and displays the generated commands used to get each value.
<#
Get-PowerShellSpecialFolders.ps1
#>
# Create an array that contains commands, how to get a particular special folder, and the values (paths) that they produce
$special_folders = @()
$names = [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder]) | Sort
ForEach ($name in $names) {
If (([Environment]::GetFolderPath("$name")) -ne "") {
$empty = $false
$path = [Environment]::GetFolderPath("$name")
$special_folders += $obj_folder = New-Object -TypeName PSCustomObject -Property @{
'Name' = $name
'Path' = $path
'Special Folder' = [string]'([' + 'Environment]::GetFolderPath(' + '"' + $name + '"))'
} # New-Object
} Else {
$empty = $true
$omit = $true
$continue = $true
} # else
} # ForEach
# Display the list of Windows PowerShell special folder commands and their values (paths) in console
$special_folders.PSObject.TypeNames.Insert(0,"Special Folders")
$special_folders | Select-Object 'Special Folder','Path' | Format-Table -AutoSize -Wrap
# Create an array that contains the environment variables and their values
$environment_variables = @()
$variables = Get-ChildItem env:
ForEach ($item in $variables) {
$command = [string]'$env:' + $item.Name
If ($command.Contains("(x")) { $command = $command.Replace("(x"," (x") }
If ($command.Contains("(x")) { $command = [string]'"' + $command + '"' }
$environment_variables += $obj_variable = New-Object -TypeName PSCustomObject -Property @{
'Environment Variable' = $command
'Name' = $item.Name
'Value' = $item.Value
} # New-Object
} # ForEach
# Display the list of Windows PowerShell environment variables and their values in console
$environment_variables.PSObject.TypeNames.Insert(0,"Environment Variables")
$environment_variables | Select-Object 'Environment Variable','Value' | Format-Table -AutoSize -Wrap
# Source: http://windowsitpro.com/powershell/easily-finding-special-paths-powershell-scripts
# Source: http://ss64.com/ps/syntax-env.html
@auberginehill
Copy link
Author

auberginehill commented Feb 23, 2017

A sample output with redacted paths, folder names and environment variable values (leaving the generated PowerShell commands, how to get each value):

Notes:

  • The available/displayed commands (under 'Special Folder' and 'Environment Variable' headers) will vary from machine to machine.
  • The generated values under 'Path' and 'Value' will vary from user to user.
  • The redacted 'Path' values are 'FullPath' -type values pointing to a directory. The redacted values under the 'Value' header are mostly paths pointing to a directory, but usually contain also other types of information as well, such as the number of logical processors or the computer name.

PS C:\Temp> .\Get-PowerShellSpecialFolders.ps1

Special Folder Path
-------------- ----
([Environment]::GetFolderPath("AdminTools"))
([Environment]::GetFolderPath("ApplicationData"))
([Environment]::GetFolderPath("CDBurning"))
([Environment]::GetFolderPath("CommonAdminTools"))
([Environment]::GetFolderPath("CommonApplicationData"))
([Environment]::GetFolderPath("CommonDesktopDirectory"))
([Environment]::GetFolderPath("CommonDocuments"))
([Environment]::GetFolderPath("CommonMusic"))
([Environment]::GetFolderPath("CommonPictures"))
([Environment]::GetFolderPath("CommonProgramFiles"))
([Environment]::GetFolderPath("CommonProgramFilesX86"))
([Environment]::GetFolderPath("CommonPrograms"))
([Environment]::GetFolderPath("CommonStartMenu"))
([Environment]::GetFolderPath("CommonStartup"))
([Environment]::GetFolderPath("CommonTemplates"))
([Environment]::GetFolderPath("CommonVideos"))
([Environment]::GetFolderPath("Cookies"))
([Environment]::GetFolderPath("Desktop"))
([Environment]::GetFolderPath("DesktopDirectory"))
([Environment]::GetFolderPath("Favorites"))
([Environment]::GetFolderPath("Fonts"))
([Environment]::GetFolderPath("History"))
([Environment]::GetFolderPath("InternetCache"))
([Environment]::GetFolderPath("LocalApplicationData"))
([Environment]::GetFolderPath("MyDocuments"))
([Environment]::GetFolderPath("MyMusic"))
([Environment]::GetFolderPath("MyPictures"))
([Environment]::GetFolderPath("MyVideos"))
([Environment]::GetFolderPath("NetworkShortcuts"))
([Environment]::GetFolderPath("Personal"))
([Environment]::GetFolderPath("PrinterShortcuts"))
([Environment]::GetFolderPath("ProgramFiles"))
([Environment]::GetFolderPath("ProgramFilesX86"))
([Environment]::GetFolderPath("Programs"))
([Environment]::GetFolderPath("Recent"))
([Environment]::GetFolderPath("Resources"))
([Environment]::GetFolderPath("SendTo"))
([Environment]::GetFolderPath("StartMenu"))
([Environment]::GetFolderPath("Startup"))
([Environment]::GetFolderPath("System"))
([Environment]::GetFolderPath("SystemX86"))
([Environment]::GetFolderPath("Templates"))
([Environment]::GetFolderPath("UserProfile"))
([Environment]::GetFolderPath("Windows"))


Environment Variable Value
-------------------- -----
$env:ALLUSERSPROFILE
$env:APPDATA
$env:CommonProgramFiles
"$env:CommonProgramFiles (x86)"
$env:CommonProgramW6432
$env:COMPUTERNAME
$env:ComSpec
$env:HOMEDRIVE
$env:HOMEPATH
$env:LOCALAPPDATA
$env:LOGONSERVER
$env:NUMBER_OF_PROCESSORS
$env:OS
$env:Path
$env:PATHEXT
$env:PROCESSOR_ARCHITECTURE
$env:PROCESSOR_IDENTIFIER
$env:PROCESSOR_LEVEL
$env:PROCESSOR_REVISION
$env:ProgramData
$env:ProgramFiles
"$env:ProgramFiles (x86)"
$env:ProgramW6432
$env:PSModulePath
$env:PUBLIC
$env:SESSIONNAME
$env:SystemDrive
$env:SystemRoot
$env:TEMP
$env:TMP
$env:USERDOMAIN
$env:USERDOMAIN_ROAMINGPROFILE
$env:USERNAME
$env:USERPROFILE
$env:windir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment