PoshCode Archive  Artifact [0b10e486eb]

Artifact 0b10e486ebc4b8e84e089ae3d4dd71e57d2775ab7c032129931b418e06706d83:

  • File Exchange-Services.ps1 — part of check-in [2e557b8b9e] at 2018-06-10 13:28:34 on branch trunk — This script checks services on Exchange Servers and restarts them if needed. (user: Littlegun size: 1001)

# encoding: ascii
# api: powershell
# title: Exchange Services
# description: This script checks services on Exchange Servers and restarts them if needed.
# version: 0.1
# author: Littlegun
# license: CC0
# x-poshcode-id: 3639
# x-archived: 2012-09-21T03:30:01
# x-published: 2012-09-14T11:00:00
#
#
#Requires input from the user
$Server = read-host "Enter Exchange Server Name"

#Finds only the services that contain "Exchange"
$Status = (Get-Service -ComputerName $server |Where-object {$_.Displayname -like "*Exchange*"})

#Displays which Exchange Services are stopped
  foreach ($Name in $status) {
     IF ($Name.status -eq "Stopped"){Write-Host $Name.displayname "was stopped" -foreground red}} 

#Starts all stopped services
  foreach ($Name in $status) {
     IF ($Name.status -eq "Stopped"){Start-Service -InputObject $Name}}

#Displays all Exchange services and their Status  
Get-Service -ComputerName $server |Where-object {$_.Displayname -like "*Exchange*"
}