Skip to content

Instantly share code, notes, and snippets.

@arcanadev
Last active July 22, 2022 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arcanadev/c8d5da085d4f3d50584d62041da9b657 to your computer and use it in GitHub Desktop.
Save arcanadev/c8d5da085d4f3d50584d62041da9b657 to your computer and use it in GitHub Desktop.
Query job history and write to a CSV file #adTempus #api #version4 #powershell

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.

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment