Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, June 5, 2019 7:22 AM
i am looking syntax to ran PowerShell script on multiple machines via PSEXEC tool. just want to know needs to copy PS1 file locally on remote machines before ran from PSEXC? <o:p></o:p>
it is possible to ran PS1 from central or share location on multiple computers using PSEXEC<o:p></o:p>
All replies (4)
Wednesday, June 5, 2019 9:19 AM
Hi,
Thanks for your question.
1. Ensure script in the location (c:\temp_ below on each remote server. servers.txt contains a list of IP addresses (one per line).
psexec @servers.txt -u <username> cmd /c "powershell -noninteractive -file C:\temp\script.ps1"
2. Yes, you need to copy the PS1 file locally on remote machines, this is because of the double hop problem.
/en-us/powershell/scripting/learn/remoting/ps-remoting-second-hop?view=powershell-6
3. No, you can't run the ps1.file from shared folder on remote computers. But you can try to use powershell command to copy the file to remote computers and then execute it.
Tips: you may don't psexec tool, powershell "Invoke-command" cmdlet also can help do that.
For example:
$computers=get-content -Path "c:\temp\computers.txt"
$file="c:\temp\test.ps1"
foreach($computer in $computers)
{
Copy-Item -Path $file -Destination "\\$computer\c$\windows\temp\test.ps1"
Invoke-Command -ComputerName $computer -ScriptBlock {
c:\windows\temp\test.ps1 }
}
Best regards,
Lee
Just do it.
Wednesday, June 5, 2019 9:38 AM
Thanks if possible please provide same example using PSEXEC tool<o:p></o:p>
PowerShell script on multiple machines via PSEXEC tool<o:p></o:p>
Thursday, June 6, 2019 9:46 AM
Hi,
Function psexec is for remote execution of scripts that sit on remote computer.
psexec @servers.txt -u <username> cmd /c "powershell -noninteractive -file C:\temp\script.ps1"
Best regards,
Lee
Just do it.
Friday, July 5, 2019 2:06 AM
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,
Lee
Just do it.