0

I want to run the following commands in CMD simultaneously :

del /q "\\server-name\D$\TestFolder\*"
FOR /D %%p IN ("\\server-name\D$\TestFolder\*.*") DO rmdir "%%p" /s /q

del /q "\\server2-name\D$\TestFolder\*"
FOR /D %%p IN ("\\server2-name\D$\TestFolder\*.*") DO rmdir "%%p" /s /q

What this does is deletes contents of TempFolder in server1 and server2.

But the problem is deletion of 2nd Query takes place only after complete deletion of folder in 1st server.

I want the deletion to run simultaneously on both servers.

Please help.

user209959
  • 11
  • 2
  • First try to generalize it, so you can have a single script using using e.g. command-line arguments for the path. Then call the script twice in the background (I'm sure PowerShell have some capabilities for that) passing the correct arguments to each invocation. – Some programmer dude Jan 29 '20 at 12:48
  • @Someprogrammerdude Hey, tbh, i don't know much about this. So needed some clarity on what you said. – user209959 Jan 29 '20 at 12:53

1 Answers1

1

You can use Invoke-Command

$servers = @('server1','server2')

Invoke-Command -ComputerName $servers Credential $cred -ScriptBlock {
    Put your code in here that executes locally
}

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7

Edit: A great explanation of this is here: How to Invoke-Command the same function on remote computers in the same time (parallel)