Create Monitor Schedule in SMA

One thing in SMA that buggs me is that the scheduling in SMA doesn’t have the same flexibility like Orchestrator. A example is the Time/Date Monitor in orchestrator where you can create ha monitor that starts a runbook every 15 minutes.

So I wrote two Powershell scripts that can create a similar experience in SMA.

The first scripts creates schedules so you can have a runbook start every 15 minutes. It will name the schedules to “Every 15 minutes HH:MM” where HH:MM is the time when the runbook will run according to a 24h clock, so for 2:30 AM it will be 02:30 and for 2:30 PM it will be 14:30.

Link to the script at the bottom of the post

###################################################################
#    Writen by Mattias Lehmus, TrueSec
#    Twitter: @onelehmus
#    Blog: onelehmus.com
#
#    THIS CODE IS PROVIDED *AS IS*
###################################################################
#Variables
$WebServiceEndpoint = “https://localhost”
$Name = “Every 15 minutes”
$Description = “Schedule for RB to run every 15 minutes”
$ExpiryTime = Get-Date -Day 31 -Month 12 -Year 9999
$Hour = 0
$Minute = 0
While($Hour -ne 24){
While($Minute -ne 60){
#Create Variables
$StartTime = Get-Date -Hour $Hour -Minute $Minute -Second 0
$TimeText = Get-date -Hour $Hour -Minute $Minute -format HH:mm
$Name = “Every 15 Minutes $TimeText”
Set-SmaSchedule -WebServiceEndpoint $WebServiceEndpoint -Name $Name -Description $Description -ScheduleType DailySchedule -StartTime $StartTime -ExpiryTime $ExpiryTime -DayInterval 1
$Minute = $Minute + 15
Write-Output ” Created Shedule $Name”
}
$Minute = 0
$Hour = $Hour + 1
}

Now when we got 96 new schedules  we need to connect them to the runbook that should start every 15 minutes. I will connect them to my runbook Monitor-ADFS-UserToDelete that has two parameters. OU that will be set to “Disabled Accounts” and PasswordAge that will be set to “180”

Link to the script at the bottom of the post

###################################################################
#    Writen by Mattias Lehmus, TrueSec
#    Twitter: @onelehmus
#    Blog: onelehmus.com
#
#    THIS CODE IS PROVIDED *AS IS*
###################################################################
#Variables
$WebServiceEndpoint = “https://localhost”
$RunbookName = “Monitor-ADDS-UsersToDelete”
$RunbookParameters = @{“OU”=”Disabled Accounts”;”PasswordAge”=”180″;}
$SheduleName = “Every 15 Minutes”
#Get Shedule(s)
$Shedules = Get-SmaSchedule -WebServiceEndpoint $WebServiceEndpoint | where name -like “$SheduleName*”
#Add runbook to shedule
IF($Shedules.count -gt 1){
ForEach($Shedule in $Shedules){
$SheduleName = $Shedule.Name
$Add = Start-SmaRunbook –WebServiceEndpoint $WebServiceEndpoint –Name $RunbookName  –ScheduleName $SheduleName -Parameters $RunbookParameters
IF($Add -eq $null){
Write-Output “Did not add runbook $RunbookName to schedule $SheduleName”
}
IF($Add -ne $null){
Write-Output “Added runbook  $RunbookName to schedule $SheduleName”
}
    }
}
IF($Shedules.count -eq 1){
$SheduleName = $Shedule.Name
$Add = Start-SmaRunbook –WebServiceEndpoint $WebServiceEndpoint –Name $RunbookName  –ScheduleName $SheduleName -Parameters $RunbookParameters
IF($Add -eq $null){
Write-Output “Did not add runbook $RunbookName to schedule $SheduleName”
}
IF($Add -ne $null){
Write-Output “Added runbook  $RunbookName to schedule $SheduleName”
}
}
IF($Shedules.Count -eq 0){
Write-Output “No schedule with name $SheduleName found”
}
That’s everything!
Now my runbook Monitor-ADDS-UsersToDelete will run every 15 minutes with the defined parameters.
Hope that this can give some ideas how to schedule SMA like Orchestrator
Link to Scripts:
//Mattias
The scripts in the blog post are AS IS, test before using in production
This entry was posted in Orchestrator, Powershell, SMA and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s