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.

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!