137

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

0

3 Answers 3

227

This is the shortest way:

$env:APPDATA

or for local app data:

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

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')
3
  • 4
    Slightly shorter version: [Environment]::GetFolderPath('ApplicationData') Apr 12, 2012 at 22:50
  • all this gives me is 'ApplicationData', not the path. Aug 27, 2015 at 4:02
  • How to list all Special Folder variable?
    – KevinBui
    Jan 22, 2022 at 23:02
5
$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, privacy policy and cookie policy

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