141

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

Martin Buberl
  • 45,844
  • 25
  • 100
  • 144

3 Answers3

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
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
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