This is one of the most demanded features in SCOM. As a SCOM admin, we were eagerly waiting for it and Microsoft had introduced this feature in SCOM 2016 for the first time and is available on the latest version of the SCOM products as well. This feature reduced a lot of manual work done by a SCOM admin.

We can get more information about how it works in the following article.

 

https://docs.microsoft.com/en-us/powershell/module/operationsmanager/new-scommaintenanceschedule?view=systemcenter-ps-2016

 

But here I will discuss it in more details so that You as a SCOM admin can automate this using PowerShell, based on the requirement you have. I will discuss here 2 types of requirements and how this functionality works when we are trying to create it from PowerShell.

 

Let’s see this with examples: –

 

I am trying to Schedule a MM which would run on 1st Sunday of every Month.

Now we can achieve that using the following PowerShell scripts.

Import-Module Operationsmanager

$monitoringobject=Get-SCOMClass -DisplayName "Windows Computer" | Get-SCOMClassInstance | where {$_.displayname -eq "SQLSERVER.lab.com"}

New-SCOMMaintenanceSchedule -Name "MonthlyTest1" -Recursive $true -Enabled $true -MonitoringObjects $monitoringobject.Id -ActiveStartTime "11-25-2019 05:06:00" -ActiveEndDate "11-15-2020 05:06:00" -Duration 60 -ReasonCode "PlannedOther" -Comments "Sourav" -FreqType 32 -FreqInterval 1 -ComputerName localhost

 

This would be looks like below.

 

 

 

The switch -FreqType Specifies when the job is to be executed. The acceptable values for this parameter are:

  • 1 (once)
  • 4 (daily)
  • 8 (weekly)
  • 16 (monthly)
  • 32 (Monthly, relative to parameter FreqInterval)

 

I have Used -Freqtype 32 which says that it will run Monthly. To set the value that when or which day of week it will run than we need to use switch -FreqInterval

 

These are the value which we can use. If you use -FreqInterval 1, that means you want it to run on 1st Sunday.  If you use -FreqInterval 2, that means you want it to run on 1st Monday.

-FreqInterval 3 = 1st Tuesday

-FreqInterval 4 = 1st Wednusday

-FreqInterval 5 = 1st Thursday

-FreqInterval 6 = 1st Friday

And so on……

 

—- 1 = Sunday —- 2 = Monday —- 3 = Tuesday —- 4 = Wednesday —- 5 = Thursday —- 6 = Friday —- 7 = Saturday —- 8 = Day —- 9 = Weekday —- 10 = Weekend day

 

The above piece of code will create the MM scheduler in SCOM. Now I want to change First Sunday to Second Sunday of the Month.

So, we need to use FreqrelativeInterval switch and we need to edit the MM schedule. I have edited the same MM schedule which i had created above.

 

$Scheduler = Get-SCOMMaintenanceScheduleList | ? {$_.ScheduleName -like 'MonthlyTest1'}

Edit-SCOMMaintenanceSchedule -ScheduleId $Scheduler.ScheduleId -FreqRelativeInterval 2

 

 

Here I have used switch -FreqRelativeInterval 2. In same way if you want to run MM on 3rd Sunday than use FreqRelativeInterval 4 and so on…

 -FreqRelativeInterval

Day that the job is executed. This is mandatory if the schedule is anything other than OnceRecurrence schedule. The value depends on the value of FreqType.

This parameter can be one of the following values:

  • 1 (First)
  • 2 (Second)
  • 4 (Third)
  • 8 (Fourth)
  • 16 (Last)

I hope this explains. I would like to hear you from more if you have any queries.

Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *