PowerShell scripts in Orchestrator RunBooks
I'm in need of a script to scrub an incoming Incident's Description and pull out Title, Assigned To, Affected User, and strip out double CRs from the Description, itself. Because there is no PowerShell Activity (GRRRRR) for Incidents, I'm trying to run my script out of a "Run .Net Script" widget in a RunBook. Problem is I can run the script in an ISE and it works. I run the RB and it returns Success, but nothing is updated. Here's the code:
PowerShell {
Import-Module Smlets
$AssignedToUserRelClass = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$
$AffectedUserRelClass = Get-SCSMRelationshipClass -Name System.WorkItemAffectedUser$
$IRClass = Get-SCSMClass -Name System.WorkItem$
$IRObject = Get-SCSMObject -Class $IRClass -filter "ID -eq {ID from "GetIncident"} <-- pull from a previous Get SCSM Object ex. IR9172
$Description = $IRObject.Description
$UpdatedDescription = $Description -replace '\r\r',[Environment]::NewLine
$title = $matches['content']
$title = $title.Substring(0, [math]::min( $title.Length, 250) )
$AgentID = $matches['content']
$AgentFilter = 'UserName -eq "'+$AgentID.Trim()+'"'
$Agent = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.AD.User$) -filter $AgentFilter | Where-Object {(-not $_.IsDeleted ) -and ($_.UPN -ne $null) }
$x = $UpdatedDescription -match "Global ID (?<content>.*)\n"
$UserID = $matches['content']
$UserFilter = 'UserName -eq "'+$UserID.Trim()+'"'
$User = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.AD.User$) -filter $UserFilter | Where-Object {(-not $_.IsDeleted ) -and ($_.UPN -ne $null) }
try {New-SCSMRelationshipObject -RelationShip $AssignedToUserRelClass -Source $IRObject -Target $Agent -Bulk } catch { continue } <-- in case there was a typo and no AD Object was returned.
try {New-SCSMRelationshipObject -RelationShip $AffectedUserRelClass -Source $IRObject -Target $User -Bulk } catch { continue }
Set-SCSMObject -SMObject $IRObject -Property Description -Value $UpdatedDescription
What is the issue and is there a workaround?
TIA
Best Answer
-
Brian_Wiest Customer Super IT Monkey ✭✭✭✭✭When you say it works in ISE. Is that an ISE session from the runbook server or local? Best test is to log into the Runbook server with the service account and use ISE to test the script.
2
Answers
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\OnlyUseLatestCLR
Type : REG_DWORD