Start & Stop all OpsMgr Services on all SCOM Management Servers in a mass with Powershell

Description :

This Powershell Script is basically intended to stop and start OpsMgr related services (“cshost”, “healthservice”, “omsdk”) on all SCOM Management Servers in a mass. This script can be used to stop and start other windows services too. You basically need to enter the server and service name into the related arrays.

The Script is also available on TechNet Script Gallery for download.
https://gallery.technet.microsoft.com/Start-Stop-all-OpsMgr-on-3231855f

Powershell Script :

# Start-or-Stop-all-OpsMgr-Services-on-all-ManagementServers.ps1
# Version 7.0
# Date: 7/17/2017
# Author: Cengiz KUSKAYA
# Description: A script to stop or start OpsMgr Services on all SCOM Management Servers in mass.

# START OpsMgr Services on Management Servers #
#######################################
$Server = @(“SCOMMS01”, “SCOMMS02”, “SCOMMS03”) # Note: Multiple Server Names can be added in the following format (“SCOMMS01”, “SCOMMS02”, “SCOMMS03”)
$ServiceList = @(“cshost”, “healthservice”, “omsdk”) # Note: Multiple Service Names can be added in the following format (“cshost”, “healthservice”, “omsdk”)
$ServicesStateStopped = get-service -computername $Server -name $ServiceList

foreach ($Service in $ServicesStateStopped)
{
if ($Service.status -eq “Stopped”)
{
$Service | Start-Service
Write-Host ($Service).Name “Service has been STARTED on Server” $Service.MachineName “….!” -Separator ” -> ” -foregroundcolor white -backgroundcolor green
}
else
{
Write-Host ($Service).Name “Service is already in RUNNING State on Server” $Service.MachineName “….!” -Separator ” -> ” -foregroundcolor DARKRED -backgroundcolor yellow
}
}

# STOP OpsMgr Services on Management Servers #
######################################

$Server = @(“SCOMMS01”, “SCOMMS02”, “SCOMMS03”) # Note: Multiple Server Names can be added in the following format (“SCOMMS01”, “SCOMMS02”, “SCOMMS03”)
$ServiceList = @(“cshost”, “healthservice”, “omsdk”) # Note: Multiple Service Names can be added in the following format (“cshost”, “healthservice”, “omsdk”)
$ServicesStateRunning = get-service -computername $Server -name $ServiceList

foreach ($Service in $ServicesStateRunning)
{
if ($Service.status -eq “Running”)
{
$Service | Stop-Service
Write-Host ($Service).Name “Service has been STOPPED on Server” $Service.MachineName “….!” -Separator ” -> ” -foregroundcolor white -backgroundcolor red
}
else
{
Write-Host ($Service).Name “Service is already in STOPPED State on Server” $Service.MachineName “….!” -Separator ” -> ” -foregroundcolor DARKRED -backgroundcolor yellow
}
}

Source : Start & Stop all OpsMgr Services on all SCOM Management Servers in a mass with Powershell