Question:
I want to delete files on a particular folder of a remote server. I execute the following in Powershell:
1 2 |
Invoke-Command -Computer 'compname1' -ScriptBlock {Remove-Item -$args -force } -ArgumentList 'c:\BizTalkDeployment' |
I get the following error:
1 2 |
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?
Answer:
Remove the – in front of $args and re-run the script. You might even try changing the script block to:
1 2 |
Remove-Item -Path $args[0] |