How can I get the path for the application data directory (e.g. C:\Users\User\AppData\Roaming
) in PowerShell?
3 Answers
This is the shortest way:
$env:APPDATA
or for local app data:
$env:LOCALAPPDATA
-
2
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')
-
5Slightly shorter version:
[Environment]::GetFolderPath('ApplicationData')
Commented Apr 12, 2012 at 22:50 -
-
-
Impressively, this is the better option because it even works on Linux, via PowerShell core, and returns the correct value —
$HOME/.config
! Commented Feb 18 at 1:58
$TempInstallerPath="$Env:USERPROFILE\AppData\Local\Downloaded Installations"
if(Test-Path $TempInstallerPath)
{
Remove-Item "$TempInstallerPath\*" -Recurse -Force -ErrorAction 0
}