Skip to content

Commit b1f745b

Browse files
authored
Merge pull request #84220 from Natfan/patch-5
Updated "Object reference not set to an instance of an object" error
2 parents aa651e6 + bfa2757 commit b1f745b

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

articles/automation/troubleshoot/runbooks.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -391,25 +391,31 @@ If the stream contains objects, `Start-AzAutomationRunbook` doesn't handle the O
391391
Implement a polling logic, and use the [Get-AzAutomationJobOutput](/powershell/module/Az.Automation/Get-AzAutomationJobOutput) cmdlet to retrieve the output. A sample of this logic is defined here:
392392

393393
```powershell
394-
$automationAccountName = "ContosoAutomationAccount"
395-
$runbookName = "ChildRunbookExample"
396-
$resourceGroupName = "ContosoRG"
394+
$AutomationAccountName = "ContosoAutomationAccount"
395+
$RunbookName = "ChildRunbookExample"
396+
$ResourceGroupName = "ContosoRG"
397397
398-
function IsJobTerminalState([string] $status) {
399-
return $status -eq "Completed" -or $status -eq "Failed" -or $status -eq "Stopped" -or $status -eq "Suspended"
398+
function IsJobTerminalState([string]$Status) {
399+
$TerminalStates = @("Completed", "Failed", "Stopped", "Suspended")
400+
return $Status -in $TerminalStates
400401
}
401402
402-
$job = Start-AzAutomationRunbook -AutomationAccountName $automationAccountName -Name $runbookName -ResourceGroupName $resourceGroupName
403-
$pollingSeconds = 5
404-
$maxTimeout = 10800
405-
$waitTime = 0
406-
while($false -eq (IsJobTerminalState $job.Status) -and $waitTime -lt $maxTimeout) {
407-
Start-Sleep -Seconds $pollingSeconds
408-
$waitTime += $pollingSeconds
409-
$job = $job | Get-AzAutomationJob
403+
$StartAzAutomationRunbookParameters = @{
404+
Name = $RunbookName
405+
AutomationAccountName = $AutomationAccountName
406+
ResourceGroupName = $ResourceGroupName
407+
}
408+
$Job = Start-AzAutomationRunbook @StartAzAutomationRunBookParameters
409+
$PollingSeconds = 5
410+
$MaxTimeout = New-TimeSpan -Hours 3 | Select-Object -ExpandProperty TotalSeconds
411+
$WaitTime = 0
412+
while((-NOT (IsJobTerminalState $Job.Status) -and $WaitTime -lt $MaxTimeout) {
413+
Start-Sleep -Seconds $PollingSeconds
414+
$WaitTime += $PollingSeconds
415+
$Job = $Job | Get-AzAutomationJob
410416
}
411417
412-
$job | Get-AzAutomationJobOutput | Get-AzAutomationJobOutputRecord | Select-Object -ExpandProperty Value
418+
$Job | Get-AzAutomationJobOutput | Get-AzAutomationJobOutputRecord | Select-Object -ExpandProperty Value
413419
```
414420

415421
## <a name="fails-deserialized-object"></a>Scenario: Runbook fails because of deserialized object
@@ -676,4 +682,4 @@ If you don't see your problem here or you're unable to resolve your issue, try o
676682

677683
* Get answers from Azure experts through [Azure Forums](https://azure.microsoft.com/support/forums/).
678684
* Connect with [@AzureSupport](https://twitter.com/azuresupport), the official Microsoft Azure account for improving customer experience. Azure Support connects you to the Azure community for answers, support, and experts.
679-
* If you need more help, you can file an Azure support incident. Go to the [Azure support site](https://azure.microsoft.com/support/options/), and select **Get Support**.
685+
* If you need more help, you can file an Azure support incident. Go to the [Azure support site](https://azure.microsoft.com/support/options/), and select **Get Support**.

0 commit comments

Comments
 (0)