Restart Service on multiple Servers
Restart Service on multiple Servers
Mit diesem Skript (neu)starten wir mit Hilfe der Powershell einen bereits gestarteten oder gestoppten Service.
Powershell anzeigen
# https://www.windows-papst.de
# Restart Service
$Path = „C:\Temp\RestartServices.txt“
$Servers = Get-Content $Path
Foreach($Server in $Servers)
{
Invoke-Command -ComputerName $Server -ScriptBlock {
$localhost = $env:computername
$RService = „SSDPSRV“
$Service = Get-Service $RService
if ($Service.Status -like „Stopped“ -or „Running“)
{
Restart-Service $RService -ErrorAction SilentlyContinue
Write-Host „Service $RService auf $localhost wurde neu gestartet“ -ForegroundColor Cyan
Start-Sleep -seconds 2
$Service.Refresh()
If ($Service.Status -eq „Running“)
{
Write-Host „Check $RService – läuft“ -ForegroundColor Green}
else {
Write-Host „Check $RService – läuft nicht“ -ForegroundColor Red}
}}}


