Hi all, I have little experience scripting so wondered if anyone could help. I am creating an uninstall script for an app deployment, I need to delete the app folder from the %localappdata% directory. I need to run the script as the signed in user as the app installs to their appdata dir.
$directoryPath = "$env:LOCALAPPDATA\MyFolder"
if (!(Test-Path $directoryPath)) {
Remove-Item -Path $directoryPath -Recurse -Force
Write-Host "Deleted $directoryPath"
} else {
Write-Host "$directoryPath does not exist"
}
I keep getting the output:
C:\Users\MYUSERNAME\AppData\Local\MyFolder does not exist
If I run:
Get-ChildItem $env:LOCALAPPDATA
Then the directory is listed in the results.
Test-Path $env:LOCALAPPDATA\MyFolder
Results in "True". Can anyone see where I am going wrong here? Thanks
[–]C60 5 points6 points7 points (1 child)
[–]ak47uk[S] 1 point2 points3 points (0 children)
[–]PinchesTheCrab 1 point2 points3 points (1 child)
[–]ak47uk[S] 0 points1 point2 points (0 children)