159

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

1

3 Answers 3

271

This is the shortest way:

$env:APPDATA

or for local app data:

$env:LOCALAPPDATA
1
  • 2
    It works in cd $env:APPDATA
    – theking2
    Commented Nov 18, 2021 at 9:23
17

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')
4
  • 5
    Slightly shorter version: [Environment]::GetFolderPath('ApplicationData') Commented Apr 12, 2012 at 22:50
  • all this gives me is 'ApplicationData', not the path.
    – Geoduck
    Commented Aug 27, 2015 at 4:02
  • How to list all Special Folder variable?
    – KevinBui
    Commented Jan 22, 2022 at 23:02
  • 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
6
$TempInstallerPath="$Env:USERPROFILE\AppData\Local\Downloaded Installations"
if(Test-Path $TempInstallerPath)
{
    Remove-Item "$TempInstallerPath\*" -Recurse -Force -ErrorAction 0
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.