Asked by:
powershel script to ran batch file for mutiple machines

Question
-
All replies
-
Hi,
Thanks for your question.
You can use "Invoke-Command" cmdlet to run commands remotely.
Invoke-Command -ComputerName Server01, Server02 -ScriptBlock {type your commands}
Best Regards,
Just do it.
-
-
Hi,
https://stackoverflow.com/questions/32125893/running-batch-script-on-remote-server-via-powershell
$cred=Get-Credential
Invoke-Command -ComputerName "Server1" -credential $cred -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /c 'C:\Users\nithi.sund ar\Desktop\Test.bat'"}
Best Regards,
Lee
Just do it.
-
-
No, when you run "Get-Credential", you will get a credential object based on a user name and password.
You can type the username and password, and the variable $cred will save the credential. You can use the credential to get a remote session with your machines.
Invoke-command can help solve your PowerShell remote session.
Best Regards,
Lee
Just do it.
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Thursday, February 28, 2019 2:56 PM
-
Save the remote machines' names or IPs in the text file.
psexec @computers.txt -d -n 5 cmd /c \\server\folder\file.BAT
You enlist the names or IPs of the PCs to contact in the computers.txt file. The -d will detach psexec, allowing to run the batch in-parallel on several machines - without psexec will wait until the batch file terminates, before switching to the next PC.Download it here:
https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
Just do it.
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Thursday, February 28, 2019 2:55 PM
-
Hi,
Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
LeeJust do it.