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
The only thing I'd implement is to do them asynchronously.
Using start-job, wait-job and receive-job.
Here's a simple example:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/9eb7dd97-f93f-4d20-9667-099b33d6d3d5/calling-async-job-from-powershell-script?forum=winserverpowershell#39608cf6-12c8-450b-82e0-1a209d3e8522
And here's a bit more complicated one:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/4d1c62b4-a6bb-40db-92ce-33a525ee4456/powershell-async-script-question?forum=winserverpowershell#daf847a4-ac14-49eb-baf8-11b8a7073b61