How can I get the path for the application data directory (e.g. C:\Users\User\AppData\Roaming
) in PowerShell?
Asked
Active
Viewed 1.6e+01k times
141

Martin Buberl
- 45,844
- 25
- 100
- 144
3 Answers
242
This is the shortest way:
$env:APPDATA
or for local app data:
$env:LOCALAPPDATA

mikemaccana
- 110,530
- 99
- 389
- 494

Dmytro Shevchenko
- 33,431
- 6
- 51
- 67
-
1It works in `cd $env:APPDATA` – theking2 Nov 18 '21 at 09:23
15
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')

Martin Buberl
- 45,844
- 25
- 100
- 144
-
4Slightly shorter version: `[Environment]::GetFolderPath('ApplicationData')` – Andy Arismendi Apr 12 '12 at 22:50
-
-
5
$TempInstallerPath="$Env:USERPROFILE\AppData\Local\Downloaded Installations"
if(Test-Path $TempInstallerPath)
{
Remove-Item "$TempInstallerPath\*" -Recurse -Force -ErrorAction 0
}

andrewsi
- 10,807
- 132
- 35
- 51

Nishendra Dissanayake
- 67
- 1
- 1