I am having trouble with a simple one liner which I am trying to push to newly imaged machines in my environment.
The script works perfectly when run locally on the machines, however the distribution package/scheduled task refused to work.
I've written the script as:
Remove-itemproperty -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run -name SecurityHealth
The install options have the execution policy set, just as I do for all other working powershell scripts.
Set-ExecutionPolicy -ExecutionPolicy Bypass
I've tried local System account (which works for my other scripts just fine) and also as my Domain admin account.
Yet when I run the scheduled task on a machine, it gives me a return code of 0. Check the machine and the registry key is still there.
So I try another way:
REG delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v SecurityHealth /f
Same as above, it works perfectly when run locally on the machine, but as a task, it returns code 1 (success apparently) and the registry remains unchanged on the machine.
This is driving me crazy as I cannot open up every machine to change this registry key manually. I have attached the policytaskhandler.exe.log if that helps