Almost christmas!
Today brings another example for handling Service Manager in in Service Management Automation (SMA), a part for Windows Azure Pack. More info: http://aka.ms/introToSMA
SMA is based on PowerShell workflow, so this could be used in other scenarios than within SMA.
This example is a runbook I use to complete an activity in service manager, in the end of most of my Service Manager runbooks.
I do this cause I want to speed up the processing and not wait for the “Check SMA Runbook Activity Complete” workflow that runs every 5 minutes but completing the Runbook activity manually
NB! This runbook is using the GUID of the Activity to get the instance.
This can be used for any type of Activity/Class that contains a Status property of the type ActivityStatusEnum
[download id=”229″]
Setup / Import
- Download or create Set-SCSMActivityStatusCompleted.ps1
- Open WAP Admin Portal
- Go to Automation
- Import Runbook
Creating Assets
This runbook uses 2 assets.
- “SCSM Server” – a variable that contains the dns name of the scsm server
- “SCSM Access Account” – a credential which contains the account to connect to the SCSM server.
To create the assets you can use the PowerShell code I posted in my last blog
you can find it here
To make this work in your environment, change the web service end point to point at your SMA server
and change the SCSM information to your servername and account info
Runbook
# workflow Set-SCSMActivityStatusCompleted { param([String]$ActivityGUID) $SCSMServer = Get-AutomationVariable -Name 'SCSM Server' $SCSMCredential = Get-AutomationPSCredential -Name 'SCSM Access Account' InLineScript { $ErrorActionPreference = "Stop" Import-Module "D:\Program Files\Microsoft System Center 2012 R2\Service Manager\PowerShell\System.Center.Service.Manager.psd1" $Instance = Get-SCSMClassInstance -Id $Using:ActivityGUID $Instance | % {$_.Status = "ActivityStatusEnum.Completed";$_} | Update-SCSMClassInstance } -PSComputerName $SCSMServer -PSCredential $SCSMCredential Write-Progress ([String] $ActivityGUID + " has been completed") }
Notice that this runbook is using the Import-Module to import the SCSM module from your installation directory.
Please change this to fit your installation.
NB! there are several different ways to do this. This example has been simplified to make it easier to use.
Using the runbook
This is a example runbook that is designed to be triggered from SCSM. Inputs include the SMA Activity GUID which we use as input
workflow New-VMBackupV2 { Param( [string]$ServiceRequestID, [string]$ServiceRequestGUID, [string]$SMAActivityGUID) $ErrorActionPreference = "Stop" #Get IDs $SelectedCIs = Get-SCSMCIFromUserInput -Question "Virtual Machine" -WorkItemGUID $ServiceRequestGUID #connect to hosts and export foreach -Parallel ($CI in $SelectedCIs) { $HostName = $CI.Hostname #get the hostname property from the result (if it exist) } CheckPoint-Workflow Set-SCSMActivityStatusCompleted -ActivityGUID $SMAActivityGUID }
Next time I will show an example of integrating this runbook into Windows Azure Pack – GridPro – Request Management.
Merry Christmas!!!