Flow Designer Powershell Action - Pass Output into Action from PS script?

huntj06
Tera Guru

I'm trying to capture the output in the flow designer "output" variable within my Powershell script. Example

 

if($action -eq "add"){
            Write-Output "Adding Mailbox Permission"
            try{
                Add-MailboxPermission -Identity $mailbox -user $upn -AccessRights fullaccess -ErrorAction Stop -Confirm:$False
                Write-host "Added Full Access"
                Add-RecipientPermission -Identity $mailbox -AccessRights sendas -Trustee $upn -ErrorAction Stop -Confirm:$False
                SNCLog-DebugInfo "SUCCESS: Added $upn to $mailbox, $task"
                Write-Output "Success"
            
            } catch{
             #$returnObj.Add("Error", $_)
              Write-Output "Error"
            }

 

As you can see, I would like to find the syntax to associate the "Error" or "Success" with a variable within flow designer. 

I'm able to access my input variables fine, like so:

$userEmail=$env:SNC_userEmail

 

Anyone have any ideas, or the proper syntax?

5 REPLIES 5

DrewW
Mega Sage
Mega Sage

From the few that I have built the PowerShell step has an output that is what ever was last output by the script.

In my case, it outputs the entire thing:

 

find_real_file.png

 

You can see the last part of the output is what I need. I'm sure I can write some javascript to parse that last word, but was hoping to find a cleaner solution..

 

Look at using " | Out-Null" at the end of commands that are putting out things that you do not want outputting to the screen.

I was able to get it working somewhat.. I ended up exporting the data to CSV and then uploading that to a SFTP server, and reimporting back into ServiceNow using a scheduled data source to make the most use of OOB functions that I can.