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.
217 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,406 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 98,621 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. Andreas Baumgarten 98,621 Reputation points MVP
    2021-05-20T11:58:49.857+00:00

    Hi @Michal ,

    have you tried to use a different name for the variable $output ? For instance $result or $outputUser ... anything different than $output.

    ----------

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

    Regards
    Andreas Baumgarten


  2. Michal 196 Reputation points
    2021-05-21T06:55:53.667+00:00

    @Andreas Baumgarten

    Whole code looks like this:

    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  
        $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 -ne $null) {  
          
            foreach ($user in $user_GC) {  
          
            $result = @{   
            $Fname = $user.GivenName  
            $Lname = $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()  
            }  
            $NewUserExists = $true  
            }  
          }  
    

    To sums this up. I need to know how to subscribe to data from powershell output in my runbook.
    For example in this case I would like to send e-mail and in it's subject there would be GUID of each new user that was found in my script.

    0 comments No comments

  3. Andreas Baumgarten 98,621 Reputation points MVP
    2021-05-21T08:21:02.933+00:00

    Hi @Michal ,

    In general: Every variable of a PowerShell script needs to be published by the Run .Net Script activity separated. If you publish the variable $result it will contain just the information it is a System.Collections.Hashtable . You can't use $result.email in later Runbook activities

    If you want the variables $Fname, $Email, $GUID separated you have to publish all these variables separated in the Run .Net Scriptactivity.

    Easy script for testing:

    $result = @{  
    Fname = 'Peter'  
    Lname = 'Pan'  
    Email = 'peter.pan@test.local'  
    GUID = 'peter.pan'  
    }  
      
    $Firstname = 'Peter'  
    $Lastname = 'Pan'  
    $EmailAddress = 'peter.pan@test.local'  
    $userGUID = 'peter.pan'  
    

    This it looks like in Orchestrator:

    98555-image.png

    98440-image.png

    ----------

    (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

  4. Michal 196 Reputation points
    2021-05-21T11:02:11.927+00:00

    Dear @Andreas Baumgarten

    I've tried to separate each value in my script:

    98574-11.png

    And here it is in Orchestrator:

    98597-22.png

    Problem is in runbook tester I don't see these variables. I tried to pass e-mail to get user activity but it crashes (it works when i type e-mail as plain text)

    0 comments No comments