Synopsis:
Enumerates all Exchange Services, UI allows selection for restarting selected services, and reloads UI to ensure services are back running.
Change Log 1.00:
3/17/2019 – Inital pre-flight version
3/18/2019 – Added GUI, selection process, and progress bar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
<# Notes: By EPIC TECIM.COM 2019 Synopsis: Enumerates all Exchange Services, UI allows selection for restarting, and reloads UI to ensure services are back running. Change Log 1.00: 3/17/2019 - Inital pre-flight version 3/18/2019 - Added GUI, selection process, and progress bar #> #Add EX2010 Snapin and AD Module Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 -ErrorAction SilentlyContinue Import-Module ActiveDirectory #Setup Variables $results= @() $i = 0 $computers = Get-TransportServer | ?{$_.name.tostring()} #Grab all the Exchange Services Do { $results= @() ForEach ($computer in $computers) { $results+= Get-Service -ComputerName $computer | ?{$_.Name -match "msexchange" -and $_.name -ne "MSExchangeMonitoring" -and $_.name -ne "MSExchangePop3" -and $_.name -ne "MSExchangeImap4"} | select machinename, name, displayname, status } #Output results to Grid $selection = $results | Sort-Object -property MachineName | Out-GridView -passthru -title 'Restart Exchange Services' If ( !$selection ) { Write-Host -ForegroundColor yellow -backgroundcolor black "Reloaded Servers Status" } Else { # Display server names and their IP addresses Write-Warning "The following exchange services will be restarted:" Foreach ($select in $selection) { Write-Host $select.machinename : $select.name } # Confirm if you want to proceed Write-Host -nonewline "Do you want to proceed? (Y/N): " $Response = Read-Host Write-Host " " # If response was different that Y script will end If ( $Response -eq "N" ) { Write-Warning "Exited" Exit } Else { # Counts the selection $count = $selection.machinename.count ForEach($Select in $Selection) { # provides progress status bar $i = $i + 1 $pct = $i/$count * 100 $server = $select.MachineName $service = $select.displayname Write-Progress -Activity "Restarting $service on $server" -Status "Restarting Service $i of $count" -PercentComplete $pct Restart-Service -InputObject $(Get-Service -Computer $select.MachineName -Name $select.displayname) -WhatIf Write-Host -ForegroundColor yellow -BackgroundColor black "$computer : Restarted $service" } Write-Progress -Activity "Restart Exchange Services" -Status "Ready" -Completed } Write-Host -ForegroundColor yellow -BackgroundColor black "Reloading Services..." } } #Reloop to load Exchange Services While ( $selection -ne $null) |