Powershell Remove-Item cmdlet fails only when deployed
I've got a Powershell script that stops a process and then removes the folders for where that software lives using the Remove-Item cmdlet. When running this locally on the machine it works. When attempting to do this via PDQ Deploy, it fails with a permissions error stating that "Access to the path is denied". However, the deploy user has rights to the directories mentioned. We're using the -Force flag as well.
I was suspecting that the process was not terminating and access was being denied due to the files being in use, however sending a Powershell command to kill the process (without removing any files) is successful via PDQ.
Comments
https://social.technet.microsoft.com/Forums/windows/en-US/98b70109-7f41-4f66-8fe8-d7e241ad5453/removeitem-force-fails-with-quotaccess-deniedquot-not-without-force?forum=winserverpowershell
Thanks for the suggestion, Wei, however removing the -Force flag returns the same results.
Try put a .txt file under c:\ drive, delete that file with PowerShell and see if you still get the same error.
Try run your current PoSH script as local system instead of "Deploy user".