本文件已封存並已停止維護。

GetLibraryAuditRecords.ps1

更新日期: 2009年9月

適用於: Virtual Machine Manager 2008, Virtual Machine Manager 2008 R2, Virtual Machine Manager 2008 R2 SP1

When a System Center Virtual Machine Manager (VMM) job completes, an audit record is saved that lists the changes that the job made to the VMM object. To access the audit record information for a job, get the job by using the Get-Job cmdlet with the Full parameter. The Full parameter indicates that the job should be returned with an audit record.

The following script gets all library refresh jobs and then lists the previous and new values for the properties that were changed during each of the jobs.

Disclaimer


# Filename:      GetLibraryAuditRecords.ps1
# Description:   Gets all library refresh jobs, and then
#                lists the previous and new values for the 
#                properties that were changed for each job.

# Get the VMM server.
Get-VMMServer "VMMServer01.Contoso.com" | out-null

# Get all library refresh jobs. Because Windows PowerShell 2.0 also contains a Get-Job cmdlet,
# qualify that you are using the VMM Get-Job cmdlet by specifying the VMM snap-in.
$LibraryJobs = Microsoft.SystemCenter.VirtualMachineManager\Get-Job -all | Where {$_.Name -eq "Refresh Library share"}

# Get the audit records for each library refresh job.
ForEach ($LibJob in $LibraryJobs)
{
   $FullLibJob = Microsoft.SystemCenter.VirtualMachineManager\Get-Job -Job $LibJob -Full

   # Get and list the changed properties for each audit record.
   Foreach ($AuditRecord in $FullLibJob.AuditRecords) 
   {
      Write-Host ""
      Write-Host "Property:" $AuditRecord.Name
      Write-Host "Previous value:" $AuditRecord.Previous.Value
      Write-Host "New value:" $AuditRecord.New.Value
      Write-Host ""
      Write-Host "#####################################################"
   }
}
顯示: