System Center Orchestrator 2019 + Powershell script = problem with passing hash table properties

Michal 196 Reputation points
2021-05-20T11:24:52.443+00:00

Hello everyone,

I'm trying to orchestrate user creation in SC Orchestrator.
Workflow would look like this:

PS Script to collect new user data > For each found user create Service Manager request > Collect data from Service Manager and pass them to Create user activity in Orchestrator

1st step is done and main code block for output looks like this:

if ($user_GC -ne $null) {  
  
 $output = foreach ($user in $user_GC) {  
   
  $properties = @{  
    'FirstName' = $user.GivenName  
    'LastName' = $user.Surname.Substring(0,1)+($user.Surname.Substring(1).tolower())  
    'Email' = $user.GABCustomUser3  
    'Department' = $user.Department  
    'JobTitle' = $user.Title  
    'Organization' = 'test'  
    'GUID'= ($user.GivenName.ToLower()).Substring(0,1)+'.'+$user.Surname.ToLower()  
    }  
    New-Object -Type psobject -Property $properties  
    $NewUserExists = $true  
 }  
 }  

Output of $output variable in Orchestrator looks like this:
@{Department=; Organization=test; JobTitle=; LastName=Test; Email=testing@test .com; FirstName=test; GUID=t.test}

In Powershell I can look for found user properties by calling for example $output.FirstName but in Orchestrator it simply fails with information that such variable does not exist.

Could you please help me with this one?

System Center Orchestrator
System Center Orchestrator
A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.
218 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,435 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 100.4K Reputation points MVP
    2021-05-21T11:23:57.1+00:00

    Hi @Michal ,

    in general: If the variable does not contain a value the variable will not be available in Published Data

    I can't see your full script in the screenshot so I could only guess:
    The definition of all the individual variables are "inside" the $result part? If so, this doesn't work.
    Take a look on my script I posted above. The individual variables are set outside the $result .

    Just guessing:
    The variables should be set between the curly bracket in line 39 and 40 and not before line 39.

    If this is not the case please post the full script here. Otherwise it's only "guessing" how your script might looking.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Stefan Horz 3,466 Reputation points
    2021-05-25T09:18:12.387+00:00

    Hi @Michal ,
    yes, you must paste every single Variable without formatting in the Published Data tab. I would modify your script like below:

    Import-Module ActiveDirectory  
    $dateforlookup = (Get-Date).AddDays(-1)  
              
    $DC_GC = "DC01"  
    $DC_PL = "DC02"  
              
    $OU_GC = "1st distinguished name of OU"  
    $OU_PL = "2nd distinguished name of OU"  
              
    $user_PL = Get-ADUser -Server $DC_PL -SearchBase $OU_PL -Filter * -Properties mail  
    [array]$user_GC = Get-ADUser -Server $DC_GC -SearchBase $OU_GC -Filter { whenCreated -gt $dateforlookup } -Properties GivenName,Surname,GABCustomUser3,whenCreated,Title,Department | Where {$_.GABCustomUser3 -notin $user_PL.mail}   
              
    if ($user_GC.count -gt 0) {  
              
        $NewUserExists = $true  
      
        $Fname = @()  
        $GUID = @()  
        $Lname = @()  
        $Email = @()  
        $Department = @()  
        $JobTitle = @()  
        $Organization = @()  
      
      
    foreach ($user in $user_GC) {  
                
        $Fname += $user.GivenName  
        $GUID += ($user.GivenName.ToLower()).Substring(0,1)+'.'+$user.Surname.ToLower()  
        $Lname += $user.Surname.Substring(0,1)+($user.Surname.Substring(1).tolower())  
        $Email += $user.GABCustomUser3  
        $Department += $user.Department  
        $JobTitle += $user.Title  
        $Organization += 'test'  
        }  
               
    }  
           
    
    0 comments No comments

  2. Michal 196 Reputation points
    2021-05-25T09:27:55.123+00:00

    Hi @Andreas Baumgarten @Stefan Horz

    Thank you so much for your help, indeed I needed to collect informations outside of main for_each and collect them into separate variables, now it works just how I wanted to :)

    I would need to integrate it further with Service Manager but I think I will create another question if I hit the wall again.

    0 comments No comments