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
-
1
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')
-
4Slightly shorter version:
[Environment]::GetFolderPath('ApplicationData')
Apr 12, 2012 at 22:50 -
-
$TempInstallerPath="$Env:USERPROFILE\AppData\Local\Downloaded Installations"
if(Test-Path $TempInstallerPath)
{
Remove-Item "$TempInstallerPath\*" -Recurse -Force -ErrorAction 0
}