Invoke-Command, yes.
The only *-Service cmdlet that supports the computername parameter is
get-service. So you have to get a little fancy.
Gc computers.txt |% { Get-Service ‘service’ –ComputerName $_ |
Set-Service –Status Running }
Or
Gc computers.txt |% { Start-Service –InputObject ( Get-Service
‘service’ –ComputerName $_ ) }
From: [email protected] [mailto:[email protected]] On
Behalf Of Rubens Almeida
Sent: Thursday, January 14, 2016 11:19 AM
To: David McSpadden; [email protected]
Subject: RE: [NTSysADM] run a command in a batch or powershell
Quick and dirty PS:
GC computers.txt | % { start-service “service” -computer $_ }
Or this
Invok-command -computer (GC computers.txt) -scriptblock {start-service
“service”}
Hope that helps!
Sent from Outlook Mail<http://go.microsoft.com/fwlink/?LinkId=550987> for
Windows 10 phone
From: David McSpadden<mailto:[email protected]>
Sent: Thursday, January 14, 2016 2:00 PM
To: [email protected]<mailto:[email protected]>
Subject: [NTSysADM] run a command in a batch or powershell
I want to run the same command against 30 workstations using a batch or
powershell
I have a list of computernames called computers.txt
Lets say I want to run
SC \\Computername<file:///\\Computername> (from computers.txt) start “Service”
How do I get that to read the computers.txt and run the SC command against each?
David McSpadden
System Administrator
Indiana Members Credit Union
P: 317.554.8190
[Description: Description: imcu email icon]<http://imcu.com/> [Description:
Description: facebook email icon] <https://www.facebook.com/IndianaMembersCU>
[Description: Description: twitter email icon]
<https://twitter.com/IndMembersCU>
[Description: Description: email logo]
[http://www.amuletsolutions.com/images/mcp.gif]<http://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0ahUKEwjFztf-tePJAhXK5iYKHcPtAxEQjRwIBw&url=http://www.amuletsolutions.com/awards.aspx&bvm=bv.110151844,d.amc&psig=AFQjCNHkrx8CednTEOOq4zUxYyrRUGzUsg&ust=1450459757284499>
This e-mail and any files transmitted with it are property of Indiana Members
Credit Union, are confidential, and are intended solely for the use of the
individual or entity to whom this e-mail is addressed. If you are not one of
the named recipient(s) or otherwise have reason to believe that you have
received this message in error, please notify the sender and delete this
message immediately from your computer. Any other use, retention,
dissemination, forwarding, printing, or copying of this email is strictly
prohibited.
Please consider the environment before printing this email.