The following can be easily added to your PowerShell profile or imported as a module to create convenient variables for referencing special folder paths. For example, “$PathDesktop\blah.txt”.
##############################################################################
#.SYNOPSIS
# Gets the path to the system special folder identified by the folder name.
#
#.DESCRIPTION
# This function is equivalent to the Environment.GetFolderPath method.
#
#.PARAMETER Folder
# An Environment.SpecialFolder enumeration value which can be specified as
# a string or literal in PowerShell (see example.)
#
#.EXAMPLE
# Get-SpecialFolder Favorites | Set-Location
#
#.RETURNVALUE
# The full path to the specified system folder.
##############################################################################
function Get-SpecialFolder([Environment+SpecialFolder]$Folder) {
[Environment]::GetFolderPath($Folder)
}
function Script:Set-SpecialFolderVariable([Environment+SpecialFolder]$Folder,[String]$Description) {
Set-Variable "Path$Folder" (Get-SpecialFolder $Folder) -Scope Global -Option AllScope,ReadOnly -Description $Description -Force
}
Set-SpecialFolderVariable ApplicationData -Description "The directory that serves as a common repository for application-specific data for the current roaming user."
Set-SpecialFolderVariable LocalApplicationData -Description "The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user."
Set-SpecialFolderVariable Desktop -Description "The logical Desktop rather than the physical file system location."
Set-SpecialFolderVariable DesktopDirectory -Description "The directory used to physically store file objects on the desktop."
Set-SpecialFolderVariable Personal -Description "The directory that serves as a common repository for documents."
Set-SpecialFolderVariable MyComputer -Description "The `"My Computer`" folder."
Set-SpecialFolderVariable MyMusic -Description "The `"My Music`" folder."
Set-SpecialFolderVariable MyPictures -Description "The `"My Pictures`" folder."
Set-SpecialFolderVariable Favorites -Description "The directory that serves as a common repository for the user's favorite items."
Set-SpecialFolderVariable Recent -Description "The directory that contains the user's most recently used documents."
Set-SpecialFolderVariable SendTo -Description "The directory that contains the Send To menu items."
Set-SpecialFolderVariable Templates -Description "The directory that serves as a common repository for document templates."
Set-SpecialFolderVariable StartMenu -Description "The directory that contains the Start menu items."
Set-SpecialFolderVariable Programs -Description "The directory that contains the user's program groups."
Set-SpecialFolderVariable Startup -Description "The directory that corresponds to the user's Startup program group."
Set-SpecialFolderVariable InternetCache -Description "The directory that serves as a common repository for temporary Internet files."
Set-SpecialFolderVariable Cookies -Description "The directory that serves as a common repository for Internet cookies."
Set-SpecialFolderVariable History -Description "The directory that serves as a common repository for Internet history items."
Set-SpecialFolderVariable ProgramFiles -Description "The program files directory."
Set-SpecialFolderVariable System -Description "The System directory."
Set-SpecialFolderVariable CommonApplicationData -Description "The directory that serves as a common repository for application-specific data that is used by all users."
Set-SpecialFolderVariable CommonProgramFiles -Description "The directory for components that are shared across applications."