Getting the path of %AppData% in PowerShell

PowershellScripting

Powershell Problem Overview


How can I get the path for the application data directory (e.g. C:\Users\User\AppData\Roaming) in PowerShell?

Powershell Solutions


Solution 1 - Powershell

This is the shortest way:

$env:APPDATA

or for local app data:

$env:LOCALAPPDATA

Solution 2 - Powershell

To get the AppData directory, use the GetFolderPath method:

[Environment]::GetFolderPath([Environment+SpecialFolder]::ApplicationData)

Or as Andy mentions in his comment, simply:

[Environment]::GetFolderPath('ApplicationData')

Solution 3 - Powershell

$TempInstallerPath="$Env:USERPROFILE\AppData\Local\Downloaded Installations"
if(Test-Path $TempInstallerPath)
{
	Remove-Item "$TempInstallerPath\*" -Recurse -Force -ErrorAction 0
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartin BuberlView Question on Stackoverflow
Solution 1 - PowershellDmytro ShevchenkoView Answer on Stackoverflow
Solution 2 - PowershellMartin BuberlView Answer on Stackoverflow
Solution 3 - PowershellNishendra DissanayakeView Answer on Stackoverflow