PowerShell Desktop Variable PowerShell Desktop Variable powershell powershell

PowerShell Desktop Variable


You can use the Environment.GetFolderPath() method to get the full path to special folders:

$DesktopPath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)

This can be shortened to:

$DesktopPath = [Environment]::GetFolderPath("Desktop")

You can also get the "AllUsers" shared desktop folder (if the shortcut file is shared among all users):

[Environment]::GetFolderPath("CommonDesktopDirectory")

Check out the full list of values for the SpecialFolder Enum.


If you need $Desktop\a.txt, use this

echo ([Environment]::GetFolderPath("Desktop")+"\a.txt")


What you are looking for is known as the $home variable. It's one of PowerShell's built-in automatic variables.

It defaults to the user-profile path, so drill down to the desktop like this:

If (Test-Path "$home\Desktop\Google Chrome.lnk") {    Remove-Item "$home\Desktop\Google Chrome.lnk"}