Hi after a couple of weeks of we are back again with posts for 2014! So I will start with a little nice PSscript to have in you PS repository.
In a case I worked on for a couple of weeks ago, I needed to look up the SMTP address of a CI in SCSM, in an Orchestrator Runbook.
To do this I used a PowerShell Remote script to do the job in a runbook.
Here is the script:
$session = New-PSSession -ComputerName SERVERNAME
Invoke-Command -Session $session -ScriptBlock {
Import-Module smlets
$Userdisplayname = "USERDISPLAYNAME"
$userpreferenceclass = Get-SCSMRelationshipClass -name system.userhaspreference
$class2 = get-scsmclass -name system.user$
$user = Get-SCSMObject -class $class2 -filter ”Displayname -eq $Userdisplayname”
$mail = (Get-scsmrelatedobject –smobject $user –relationship $userpreferenceclass | where{$_.displayname –match “smtp”}).targetaddress
}
$mail = Invoke-Command -Session $session -ScriptBlock { $mail }
Remove-PSSession $Session
Here you need to change the SERVERNAME and USERDISPLAYNAME, with the SCSM server and the displayname of the CI.
The result of the script will be available in the
$mail variable.
Then I added the script to a Run.Net Script Activity.
The $mail variable now contains the SMTP address of the CI Object.
In order to publish the result to the next Activity in the runbook do the following:
Open the Run.Net Script Activity and Select [
Publish Data] then click
[Add].
Type a name, type and the variable name from the PS script. Click [OK]
The variable is now available in the bus, and can be used in other activities in the runbook.