Powershell Invoke-Command Remote Element Remote Server

I want to delete files in a specific folder on a remote server. I am doing 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 to compname1 server.

Can someone explain what I did wrong?

+5
source share
2 answers

Remove before $ args and run the script. You can even try changing the script block to:

Remove-Item -Path $args[0]
+5
source

You can also delete the folder using the UNC path:

Remove-Item \\compname1\c$\BizTalkDeployment -force
+3
source

All Articles