Partilhar via


How to get the audit trail records from a VMM Job

Today, in VMM, you can open the Administrator Console and click on the Jobs view to see all the Jobs in VMM. When you select an individual job, you can click on the "Change Tracking" tab and view any changes that were recorded in VMM as part of this job.

In this post, i will show you how to do this in PowerShell since it is not as intuitive. Basically, audit trail records that are placed in the change tracking tab are not cached on the client computer by default. the only way to surface them in powershell is to individually invoke the get-job commandlet and pass it the Job parameter while asking for the FULL job to be downloaded. the following powershell script does exactly that and displayed the audit trail records for all jobs in the system.

#get all jobs in the system
$jobs = get-job -all
foreach ($job in $jobs)
{

#get the details including the audit records for each single job in VMM
 $singlejob = get-job -job $job -full
 $auditrecordsexist = $singlejob | select AreAuditRecordsAvailable 
 if ($auditrecordsexist)
 {

#if any audit records exist, print them out
  foreach ($record in $singlejob.AuditRecords)
  { 
   $record
   $prev = $record.Previous
   $newr = $record.New
   $prev
   $newr
  }
 }
}