Michael Wu

The Life of a Cloud Engineer

  • Home
  • Resume
  • Blog
  • Contact

Posted on 01.31.17

Schedule SCOM Maintenance Mode by PowerShell GUI Tool

Updated at 01/03/2018 : The tool has been updated with the schedule feature. Please see detail information at the end of the page.

Open SCOM (System Center Operations Manager) console to start a Maintenance Mode could be slow when you are in a large environment.

So, I made my own SCOM console for the Maintenance Mode.

In this SCOM Maintenance Mode GUI tool, you can search for Windows servers. The input supports wildcard search. It will list all servers on SCOM if you leave the name blank.

First, select a server on the list. You can only start maintenance mode on one server at a time.

Then, enter a duration time (5 minutes minimum) or select a specific end time. If you enter the duration time, the end time will be the current time plus the duration time.

If you have both duration time and specific end time, specific end time will overwrite the duration time.

You might notice the form looks different when you select a specific end time. This is because the main form was created by WPF (Windows Presentation Foundation), but there is no DateTimePicker in WPF.  There is an Extended WPF Toolkit for DateTimePicker that works on Visual Studio, but I could not make it work on PowerShell.

Windows Forms have a built-in DateTimePicker, so I created a separate form for it.

The default Maintenance Mode Reason is Other(Planned). Comment is not required.

It will prompt you after click Start Maintenance Mode button. Click OK to start the maintenance mode.

To stop the maintenance mode, select the Stop Maintenance Mode tab. Select the server and click the Stop Maintenance Mode button.

You can download the script from GitHub.

The script needs to be executed by the account that has privilege in SCOM.


Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms

# SCOM Management Server Input
#$SCOMMgmtSvr = "YourManagementServer.yourDomainName"
$SCOMMgmtSvr = Read-Host "Please enter your SCOM Management Server name"

New-SCOMManagementGroupConnection -ComputerName $SCOMMgmtSvr

You can enter the SCOM Management Server name after running the script on the PowerShell console.

Or, add the server name on line 5 and comment out line 6 in the script.

Tested platform: SCOM 2012 R2, Windows Server 2012 R2, PowerShell v4.0


Update 01/03/2018 :

SCOM 2012 R2 is not able to schedule a Maintenance Mode for a server. The feature has been added to SCOM 2016. However, we are not ready to upgrade yet. So I decide to add the feature to my GUI tool.

Using PowerShell Scheduled jobs, I am able to create a PowerShell job that running the Start-SCOMMaintenanceMode cmdlet on demand. Below is the main function code.

$trigger = New-JobTrigger -Once -At $startTime
$cred = Get-Credential $userID
$options = New-ScheduledJobOption -RequireNetwork
$script = {
  Import-Module -Name OperationsManager
  New-SCOMManagementGroupConnection -ComputerName $args[2]
  $instance = Get-SCOMClassInstance $args[0]
  Start-SCOMMaintenanceMode -Instance $instance -EndTime $args[1].ToUniversalTime()
  # Remove Scheduled Job
  Unregister-ScheduledJob -Name $args[0]
}

Register-ScheduledJob -Name $selectedItem -ScriptBlock $script -Trigger $trigger -ScheduledJobOption $options -Credential $cred -ArgumentList $selectedItem, $time,$SCOMMgmtSvr

When you Register-ScheduleJob, it creates a PowerShell job that will be triggered by the Windows Task Scheduler. The Task Scheduler can be found in Task Scheduler Library -> Microsoft -> Windows -> PowerShell -> ScheduledJobs.

You can also hide the task scheduler by adding New-ScheduledJobOption -HideInTaskScheduler.

The scheduled job does not remove after it completed. So I added the Unregister-ScheduledJob to the script after started the maintenance mode.

It`s very easy to use. You just need to select the start time and end time for the maintenance mode. You will need the domain account credential with SCOM privilege.

The scheduled jobs will show in the Scheduled Maintenance Mode tab.

Please test the script in the DEV environment before you use it in Production. You can download the script from GitHub.

Remember to change the SCOM Management Server variable before you run it.

Categories:PowerShell

Recent Posts

  • Automating Resource Restriction in Azure subscriptions with Budget Alert, Automation Account, and Azure Policy
  • How to configure the Security Center via Azure Resource Manager (ARM) template
  • How to restrict Account Operators to see the password in LAPS
  • How to join a VM to a domain by PowerShell in Azure
  • How to push an existing repository from VS Code to Azure DevOps by PowerShell

Search

Categories

  • Azure
  • IIS
  • PowerShell
  • SCCM
  • VMware
  • Windows Server

Contact

Email: [email protected] | Powered By the 太初網路

Copyright © 2024 mikewu.org Disclaimer

Connect

FacebookTwitterGoogle +Linkedin