Last active
March 30, 2022 20:15
-
-
Save x-limitless-x/3f37e50e097f5800f7b65b4b019c04ab to your computer and use it in GitHub Desktop.
Easily set Veeam VMWare Maintenance Mode in SCOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module OperationsManager | |
$instanceclass = Get-SCOMClass -DisplayName "Veeam VmWare" | |
Function Time-Stamp | |
{ | |
$TimeStamp = Get-Date -Format "MM/dd/yyyy hh:mm:ss tt" | |
return "$TimeStamp - " | |
} | |
$ErrorActionPreference = 'SilentlyContinue' | |
$Servers = Get-SCOMClassInstance | Where { ($_.DisplayName -match "^AS-.*$") -or ($_.DisplayName -match "^SC-.*$") -and ($_.DisplayName -notmatch "vmhost") } | |
$Servers | Export-Csv -Path "$env:USERPROFILE\Desktop\AS-or-SC-Servers.csv" | |
function CustomMaintenaceMode | |
{ | |
Function Time-Stamp | |
{ | |
$TimeStamp = Get-Date -Format "MM/dd/yyyy hh:mm:ss tt" | |
return "$TimeStamp - " | |
} | |
function Write-HostAndOutput | |
{ | |
param | |
( | |
[Parameter(Mandatory = $true)] | |
[string]$Text | |
) | |
Write-Host "$(Time-Stamp)$Text" | |
return Write-Output "$(Time-Stamp)$Text" | |
} | |
Write-HostAndOutput "Running Main function: " -NoNewline | |
Write-HostAndOutput 'CustomMaintenaceMode' -ForegroundColor Green | |
$ErrorActionPreference = 'SilentlyContinue' | |
Write-HostAndOutput "Found $($Servers.Count) count" | |
Write-HostAndOutput "Exporting CSV to: $env:USERPROFILE\Desktop\AS-or-SC-Servers.csv" | |
$Time = ((Get-Date).AddHours(9999999)) | |
$Servers = (Import-Csv -Path "$env:USERPROFILE\Desktop\AS-or-SC-Servers.csv").DisplayName | |
$i = 0 | |
Foreach ($Server in $Servers) | |
{ | |
$i++ | |
$i = $i | |
$Instance = $instanceclass | Get-SCOMClassInstance | Where { ($_.DisplayName -match "^AS-.*$") -or ($_.DisplayName -match "^SC-.*$") -and ($_.DisplayName -notmatch "vmhost") -and ($_.DisplayName -match $Server) } | |
Write-HostAndOutput "($i/$($Servers.Count)) Setting $($Instance.DisplayName) into Maintenance Mode for $Time hours" | |
Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "SCCM Patching" -Reason "PlannedOther" | |
#Checking Maintenance Mode | |
#$Server | |
#Get-SCOMMaintenanceMode -Instance $Instance | select ManagementGroup,User,StartTime,ScheduledEndTime,Reason,Comments | fl | |
} | |
Write-HostAndOutput "Script Completed!" | |
} | |
CustomMaintenaceMode | Out-File -FilePath "$env:USERPROFILE\Desktop\AS-or-SC-Servers-ScriptOutput.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment