rtmcmullen
asked on
PowerShell Script remote execution
I have a simple powershell script that sets a service and starts it. I want to run this against a list of computers instead of typing each computer in individually... is there a way to do this with powershell?
What does the Script do specifically? While the native powershell commands like get-service and start-service do not work against remote machines, most of this can be done with .NET.
ASKER
The script sets a service to Automatic and then starts the service.
Try something like this... I havent tested it, but it should work.
########################## #####
Param($server,$list,$servi ce,[switch ]$verbose)
if($Verbose){$VerbosePrefe rence = "Continue"}
if($list)
{
foreach($srv in $list)
{
$query = "Select * from Win32_Service where Name='$service'"
$myService = get-WmiObject -query $query -computer $srv
$myService.ChangeStartMode ("Automati c")
$myService.Start()
}
}
if($server)
{
$query = "Select * from Win32_Service where Name='$service'"
$myService = get-WmiObject -query $query -computer $server
$myService.ChangeStartMode ("Automati c")
$myService.Start()
}
##########################
Param($server,$list,$servi
if($Verbose){$VerbosePrefe
if($list)
{
foreach($srv in $list)
{
$query = "Select * from Win32_Service where Name='$service'"
$myService = get-WmiObject -query $query -computer $srv
$myService.ChangeStartMode
$myService.Start()
}
}
if($server)
{
$query = "Select * from Win32_Service where Name='$service'"
$myService = get-WmiObject -query $query -computer $server
$myService.ChangeStartMode
$myService.Start()
}
ASKER
I'm a beginner with powershell, can you break this down a little for me?
Say the service is DHCP, and I wanted to call the list it would pulling from ServerList.txt
Thanks
Say the service is DHCP, and I wanted to call the list it would pulling from ServerList.txt
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin