Avatar of creative555
creative555
 asked on

question for get-service and resetiis powershell commands

Hello everyone,
I just wanted to ask you if we are doing the most efficient way of resetting IIS and validating services on multiple computers.
 
Is this command could be simplified? We only have two servers where we are resetting IIS and 5 computers where we need to validate and set services.
 
Perhaps what we are doing here is NOT the most efficient process.
 
Let me know. Thank you so much!
 
1. At the elevated PowerShell prompt, run the commands below:
      a. Reset IIS
      $pors = (get-content "f:\software\servers.txt") | select-string "por0"
      Foreach ($por in $pors) {Invoke-command –ComputerName $por –ScriptBlock {iisreset}}

      b. Set all DEV services to Automatic - Running
      $servers = get-content -path "f:\software\servers.txt"
      Foreach ($server in $servers) {Invoke-command –ComputerName $server –ScriptBlock {get-service –displayname *DEV* | set-service –startuptype automatic –status running}}

      c. Validate all DEV services status
      $services = Foreach ($server in $servers) {Invoke-command –ComputerName $server –ScriptBlock {get-service –displayname *adms* | select pscomputername,displayname,status,starttype}}
      $services |format-table -autosize
 
PowershellScripting Languages

Avatar of undefined
Last Comment
creative555

8/22/2022 - Mon
Jose Gabriel Ortega Castro

ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
creative555

ASKER
Thank you so much!!
Your help has saved me hundreds of hours of internet surfing.
fblack61