Getting the path of %AppData% in PowerShell
This is the shortest way:
$env:APPDATA
or for local app data:
$env:LOCALAPPDATA
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')
$TempInstallerPath="$Env:USERPROFILE\AppData\Local\Downloaded Installations"
if(Test-Path $TempInstallerPath)
{
Remove-Item "$TempInstallerPath\*" -Recurse -Force -ErrorAction 0
}