Retrieve and Export Azure Automation Jobs with All Parameters

This PowerShell script retrieves Azure Automation jobs from the last 7 days for a specific runbook, enriches each job with missing details, normalizes all parameters, and exports everything to a CSV file for easy analysis.

This can be incredibly useful for operational monitoring, auditing, and troubleshooting. In many environments, runbooks are triggered with dynamic input parameters, and simply viewing job summaries in the Azure portal doesn’t provide enough visibility. With this script, you get a complete view of what was run, when, by whom, and with which input values, all in one consistent dataset.

Prerequisites

# Sign in and select your subscription
Connect-AzAccount
Set-AzContext -Subscription "YourSubscriptionName"

# Import the Az.Automation module
# Install-Module Az.Automation -Force   # Uncomment if needed
Import-Module Az.Automation

Define Variables

$AutomationAccountName = 'AutomationAccountName'
$ResourceGroupName     = 'ResourceGroupName'
$RunbookName           = 'Your Runbook name'

$AutoAccount = @{
    AutomationAccountName = $AutomationAccountName
    ResourceGroupName     = $ResourceGroupName
}

Get Jobs from the Last 7 Days

$StartTime = (Get-Date).AddDays(-7)

$Jobs = Get-AzAutomationJob @AutoAccount -RunbookName $RunbookName -StartTime $StartTime

Enrich Job Objects with Missing Details

$count      = 0
$jobsCount  = $Jobs.Count

foreach ($Job in $Jobs) {
    $count++
    Write-Output "$($count) of $($jobsCount) processed → JOBID: $($Job.JobId)"

    $automationJob = Get-AzAutomationJob @AutoAccount -Id $Job.JobId

    $Job.JobParameters = $automationJob.JobParameters
    $Job.StatusDetails = $automationJob.StatusDetails
    $Job.StartedBy     = $automationJob.StartedBy
    $Job.Exception     = $automationJob.Exception
}

Collect All Parameter Names

$allParameterNames = @()

foreach ($job in $Jobs) {
    if ($job.JobParameters) {
        $allParameterNames += $job.JobParameters.Keys
    }
}

$allParameterNames = $allParameterNames | Sort-Object -Unique

Build a Consistent Output Object

$JobList = @()

foreach ($job in $Jobs) {
    $entry = [ordered]@{
        JobId         = $job.JobId
        CreationTime  = $job.CreationTime
        Status        = $job.Status
        StatusDetails = $job.StatusDetails
        StartTime     = $job.StartTime
        EndTime       = $job.EndTime
        Exception     = $job.Exception
        RunbookName   = $job.RunbookName
        HybridWorker  = $job.HybridWorker
        StartedBy     = $job.StartedBy
    }

    foreach ($param in $allParameterNames) {
        $entry[$param] = if ($job.JobParameters.ContainsKey($param)) {
            $job.JobParameters[$param]
        } else {
            $null
        }
    }

    $JobList += [pscustomobject]$entry
}

Export to CSV

$exportPath = "C:\automation\updateuser_Jobs_allproperties_and_parameters.csv"
$JobList | Export-Csv -Path $exportPath -NoTypeInformation -Delimiter ";" -Encoding UTF8

Result

After running the script, you’ll have a CSV file containing:

  • Core job metadata (ID, status, times, runbook, worker, etc.)
  • Every input parameter captured as its own column
  • A uniform structure ideal for Excel, Power BI, or automation reporting

Github

You can access the whole script on my Github Repo below.

Azure Automation Job Skript

Happy automating! 

Leave a comment