?
Solved

execute bat file on multiple machines

Posted on 2014-04-12
7
Medium Priority
?
5,824 Views
Last Modified: 2014-04-12
Hi all, i think im almost there but need some help, im trying to run the following batch command but am getting some parameters errors. Any help appreciated.

$servers =Get-Content "C:\Users\computers.txt"

foreach ( $servers1 in $servers ) {
@"

Displaying for $servers1

"@
 $execute = invoke-command -Path C:\wsusreset.bat
0
Comment
Question by:cwstad2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 39996558
$servers =Get-Content "C:\Users\computers.txt" | % {
invoke-command -computername $_ -scriptblock { invoke-command C:\wsusreset.bat }
}

Open in new window

0
 
LVL 15

Author Comment

by:cwstad2
ID: 39996567
Thanks, looks like winrm isnt enabled. Damn. I take it i have to log on to each server and enable it manually. I dont suppose you know of an equivalent script to exexute it with psexec?

thanks
0
 
LVL 29

Expert Comment

by:becraig
ID: 39996573
for /f %a  in (C:\Users\computers.txt) do psexec \\%a cmd /c C:\wsusreset.bat

That is from the command line

If you make it a .bat .cmd

for /f %%a  in (C:\Users\computers.txt) do psexec \\%%a cmd /c C:\wsusreset.bat
0
Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

 
LVL 15

Author Comment

by:cwstad2
ID: 39996589
Thanks for the reply. I created a .bat but when i run i get "cmd exited with error code 1."
0
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 39996592
I am assuming there is something happening with the .bat you are running on the server itself or maybe an issue of permissions.


you can try this:

for /f %%a  in (C:\Users\computers.txt) do psexec -u domain\username -p password \\%%a cmd /c C:\wsusreset.bat

Can you also try running the .bat file you want to execute on the servers to see if it run without errors:
psexec \\server cmd /c c:\wsusreset.bat

What are you trying to do ?
Maybe we can find an easier way ?
0
 
LVL 15

Author Comment

by:cwstad2
ID: 39996621
worked a treat thanks
0
 
LVL 40

Expert Comment

by:footech
ID: 39996951
@cwstad2 - Just an FYI, you can enable PS Remoting via Group Policy.
http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/24/an-introduction-to-powershell-remoting-part-two-configuring-powershell-remoting.aspx

When needing to run .bat files or other external programs, here's a good resource for your options in PS.
http://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question