Working in a script able to delete files in privileged folder like system 32.
But getting “File '\Windows\System32\Tryme\new 2.txt' does not exist.” on the script bellow.
According to the reponce on this:
Automox runs as SYSTEM so this issue is unlikely related to elevated privileges.
Any suggestions? What am I missing here?
Evaluation Code:
Exit 1
Remediation code:
$filePath = "C:\Windows\System32\Tryme\new 2.txt"
# Check if the file exists
if (Test-Path $filePath) {
try {
# Attempt to delete the file
Remove-Item -Path $filePath -Force -Recurse
Write-Output "File '$filePath' has been successfully deleted."
} catch {
# If an error occurs, display the error message
Write-Output "An error occurred while trying to delete the file: $_"
}
} else {
# If the file does not exist, inform the user
Write-Output "File '$filePath' does not exist."
}