Home Orchestrator

PowerShell scripts in Orchestrator RunBooks

Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭
Hi All,
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
$x = $UpdatedDescription -match "Your Question (?<content>.*)\n"
$title = $matches['content']
$title = $title.Substring(0, [math]::min( $title.Length, 250) )
$x = $UpdatedDescription -match "Agent: (?<content>.*)\n"
$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 Title  -Value $title.TrimStart()
Set-SCSMObject -SMObject $IRObject -Property Description  -Value $UpdatedDescription
$IRObject.Commit()
}

What is the issue and is there a workaround?
TIA

Best Answer

  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    Answer ✓
    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.

Answers

  • Jeff_LangJeff_Lang Customer Ninja IT Monkey ✭✭✭✭
    @Brian_Winter if i remember correctly SCORCH currently only uses PowerShell V2.0, whereas your ISE will use the latest version installed on your system. SCORCH 2019 should support PowerShell 4.0 by default

    you could try forcing SCORCH to use the PowerShell version installed on on your system by setting the below registry key

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\OnlyUseLatestCLR

    Type : REG_DWORD
    Value name : OnlyUseLatestCLR
    Value Data : 1


  • Jeff_LangJeff_Lang Customer Ninja IT Monkey ✭✭✭✭
    i forgot to mention, the server may need a reboot to make that registry key take effect
  • Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭
    No luck, my friend.  RunBook completes successfully.  the .Net script returns no errors.  But the Incident fields are not updated.  I'm going to try logging each statement as per:  https://social.technet.microsoft.com/wiki/contents/articles/30721.powershell-system-center-orchestrator-best-practice-template.aspx


  • Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
    Answer ✓
    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.
  • Brian_WinterBrian_Winter Customer Advanced IT Monkey ✭✭✭
    @Brian_Wiest , you nailed it.  I was developing on the SCSM App Server, not the SCORCH server.  Once I followed your recommendation, I saw "Data Access Service is not running...." and knew the issue.  I simply added -Computer xxxxxxxx to each SCSM cmdlet and we're working!!!

Sign In or Register to comment.