System Center Orchestrator 2022 WebAPI call using PowerShell returns status as Pending

Ashutosh Sapre 20 Reputation points
2025-11-06T15:46:05.9633333+00:00

I have a test Runbook which I am executing using PowerShell Invoke-RestMethod. I pass a server name as a parameter. Then the runbooks sends a query to ServiceNow to get the server details which are then saved to a test log file and also to a Run .Net script activity which also writes to a log file(I just wanted to test how to publish data and use it in the activities). I have added the Return Data activity, but I am not sure how to extract the result back on to the PowerShell console.

Screenshot 2025-11-06 163815

The response status comes up as Pending, but when I check the webconsole the runbook was executed successfully.

1). How can I get the correct status from the response?

2). How can I get the result on the PowerShell console as a result from the script?

The script and response I get is:

# Define variables

$runbookId = "XXXXXXXX-3455-5343-8234-XXXXXXXXXXXX" # Replace with your Runbook ID (GUID)

$serverName = "WINSERVER01" # Replace or make dynamic

# Construct the Web Service URI

$webServiceUri = "https://orchestratorapi.testdomain.local/api/Jobs"

# Define parameters to pass to the runbook

$parameters = @(

@{

Name = "ServerName"

Value = $serverName

}

)

# Create the body for the REST API call

$body = @{

RunbookId = $runbookId

Parameters = $parameters

CreatedBy = $null

} | ConvertTo-Json -Depth 3

# Invoke the runbook

$response = Invoke-RestMethod -Uri $webServiceUri `

-Method POST `

-Body $body `

-ContentType "application/json" `

-UseDefaultCredentials

# Output the response

$response.content

Response:

@odata.context : https://orchestratorapi.testdomain.local/api/$metadata#Jobs/$entity

Id : XXXXXXX-b3yt-n43s-vd22-XXXXXXXXXXXX

RunbookId : XXXXXXXX-3455-5343-8234-XXXXXXXXXXXX

Parameters : <Data><Parameter><Name>ServerName</Name><Value>WINSERVER01</Value><ID>{XXXXXXXX-xyzx-xyzx-xyzx-XXXXXXXXXXXX}</ID></Parameter></Data>

RunbookServers :

RunbookServerId :

ParentId :

ParentIsWaiting : False

Status :Pending

CreatedBy : S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxx

CreationTime : 2025-11-06T11:06:16.467+01:00

LastModifiedBy : S-1-5-21-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxx

LastModifiedTime : 2025-11-06T11:06:16.467+01:00

Authorizations : {}

Thanks!

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

Answer accepted by question author
  1. Dimple Rane 1,231 Reputation points
    2025-11-19T08:20:37.2433333+00:00
    1. To get the correct status from the response, you need to periodically check the job status until it is no longer "Pending". You can do this by making a GET request to the job status endpoint using the job ID returned in the initial response.
    2. To get the result on the PowerShell console, you need to extract the job output once the job status is "Completed".

    Here is an example of how you can achieve this:

    # Define variables  
    $runbookId = "XXXXXXXX-3455-5343-8234-XXXXXXXXXXXX" # Replace with your Runbook ID (GUID)  
    $serverName = "WINSERVER01" # Replace or make dynamic  
    $webServiceUri = "https://orchestratorapi.testdomain.local/api/Jobs"
    
    # Define parameters to pass to the runbook  
    $parameters = @(  
        @{  
            Name = "ServerName"  
            Value = $serverName  
        }  
    )
    
    # Create the body for the REST API call  
    $body = @{  
        RunbookId = $runbookId  
        Parameters = $parameters  
        CreatedBy = $null  
    } | ConvertTo-Json -Depth 3
    
    # Invoke the runbook
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ashutosh Sapre 20 Reputation points
    2025-12-04T14:26:32.29+00:00

    Thanks! I did the same. After getting the first response, I again invoke the rest method for the job ID to get the status using Do Until loop till I get a "Completed" response.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.