Query job history and write to a CSV file

Language: PowerShell

View on GitHub to download or comment.

See the Client API Examples Introduction for additional information and prerequisites.

Samples index

This PowerShell script uses the adTempus API to query the history for selected jobs and write the history to a CSV file.

  • The server parameter is the name/address of the adTempus server instance to connect to. Use "." for the local server.
  • The job parameter can be a job name or group name. To select all jobs, use "*".
  • The start and end parameters are the start and end date/time range to query.
  • The output parameter is the name of the file to write the CSV output to.

Modify the property list in select-object (line 22) to include additional properties for the instances.

get-ADTJobHistory.ps1
param (
    [string]$server = ".",
    [string]$job = "*",
    [datetime]$start=,
    [datetime]$end,
    [Parameter(Mandatory)]
    [string]$output
 )

add-type -path "c:\program files\arcana development\adtempus\4.0\ArcanaDevelopment.adTempus.Client.dll"

$adtempus=[ArcanaDevelopment.adTempus.Client.Scheduler]::Connect($server,[ArcanaDevelopment.adTempus.Shared.LoginAuthenticationType]::Windows,"","")
$context=$adtempus.NewDataContext()



$parms = New-Object ArcanaDevelopment.adTempus.Shared.InstanceQueryParameters
$parms.StartTimestamp = $start
$parms.EndTimestamp = $end
$context.GetJobs($job) | ForEach-Object {$parms.TargetObjects.Add($_.OID)}

$context.GetJobHistory($parms) | select-object -property @{Name='FullName';Expression={$_.Job.FullyQualifiedName}},@{Name='JobName';Expression={$_.Job.Name}},InstanceID,ExecutionStart,ExecutionFinish,Status | Sort-Object -property FullyQualifiedName | export-csv -Path $output

$context.Dispose()
$adTempus.Dispose()

Comments

View on GitHub to comment.