Saturday, November 30, 2019

Restart BULK Server Script

1. create CompRestart.txt on C:\ with names of servers
2. execute below powershell script



$comps = Get-Content C:\CompRestart.txt
$count = $comps.count
foreach($comp in $comps){
$pos = [array]::indexof($Comps,$Comp)
$pos = $pos + 1
Write-host "Restarting $comp $pos of $count"


#Scriptblock for SCOM Maintenance
$scom = {
Import-Module -Name OperationsManager 
$VMfqdn = $args[0]+".corp.beone.net"
$Instance = Get-SCOMClassInstance -Name "$VMfqdn"
$Time = ((Get-Date).AddMinutes(10))
Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "Applying software update" -Reason "SecurityIssue"
Write-Warning "Server $VM has been put in maintenance mode"
}
Invoke-Command -ComputerName asv-omm-01 -ScriptBlock $scom -ArgumentList $Comp
Start-Sleep 2



Restart-Computer -ComputerName $comp -Wait -For PowerShell -Timeout 180 -Delay 1 -force -ErrorAction SilentlyContinue


}

No comments:

Post a Comment