Getting the path of %AppData% in PowerShell
PowershellScriptingPowershell Problem Overview
How can I get the path for the application data directory (e.g. C:\Users\User\AppData\Roaming
) in PowerShell?
Powershell Solutions
Solution 1 - Powershell
This is the shortest way:
$env:APPDATA
or for local app data:
$env:LOCALAPPDATA
Solution 2 - Powershell
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')
Solution 3 - Powershell
$TempInstallerPath="$Env:USERPROFILE\AppData\Local\Downloaded Installations"
if(Test-Path $TempInstallerPath)
{
Remove-Item "$TempInstallerPath\*" -Recurse -Force -ErrorAction 0
}