I want to delete files on a particular folder of a remote server. I execute the following in Powershell:
Invoke-Command -Computer 'compname1' -ScriptBlock {Remove-Item -$args -force } -ArgumentList 'c:\BizTalkDeployment'
I get the following error:
Cannot find drive. A drive with the name '-c' does not exist.
c:\BizTalkDeployment is the correct path on server compname1.
Can anyone please explain what I've done wrong?
Remove the - in front of $args and re-run the script. You might even try changing the script block to:
Remove-Item -Path $args[0]
You could also remove the folder using a UNC path:
Remove-Item \\compname1\c$\BizTalkDeployment -force
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With