Hello Everyone!
Today It is my turn to write in the Coretech christmas calendar!
Currently I am working a lot 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.
The first example i want to show is an easy way to get the selected object(s) in a Service Manager Request Offering
[download id=”226″]
Setup / Import
- Download or create Get-SCSMCIFromUserInput.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 following PowerShell code
# $WebEndPoint = "https://or01.cloud.local" Set-SmaVariable -WebServiceEndpoint $WebEndPoint -Name "SCSM Server" -Value "sm01.cloud.local" #Create credential object $credPassWord = ConvertTo-SecureString "Start123!" -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ("cloud\Administrator", $credPassWord) #Create Credential Asset in SMA using the newly created credential object Set-SmaCredential -WebServiceEndpoint $WebEndPoint -Name "SCSM Access Account" -Value $cred
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 Get-SCSMCIFromUserInput{ param([String]$WorkItemGUID, [String]$Question) $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:WorkItemGUID $XML = [XML] $Instance.UserInput $AnswerXML = [XML]($XML.UserInputs.UserInput | ? { $_.Question -eq $Using:Question }).Answer foreach ($Id in $AnswerXML.Values.Value.Id) { $returnObj = New-Object -TypeName PSOBject $EMO = (Get-SCSMClassInstance -Id $Id).EnterpriseManagementObject foreach ($value in ($EMO.Values | Sort Type)){ $returnObj | Add-Member -MemberType NoteProperty -Name $value.Type -Value $value.Value } $returnObj } } -PSComputerName $SCSMServer -PSCredential $SCSMCredential #Get-SCSMCIFromUserInput "d369e510-4626-baad-b325-c21ac3e98cba" "Virtual Machine" }
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 service request GUID which we use to send to the Get-SCSMCIFromUserInput.
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) } }
Merry Christmas!!!
Thanks Jakob, This is useful. I was looking at a way to get user input from an SCSM request offering and this looks like it would work. We were originally thinking of building the user input into a string array and then converting this string array into a hashtable or idictionary object to pass to start-smarunbook.
Lance