You can refer to my previous comment. There is an official solution that can be obtained through our technical support. It is built into the product, but requires "activation"

Thanks,
Fedor
Code: Select all
$VmNames = Get-VM -ComputerName XXXX, YYYY, ZZZZ
Foreach ($VmName2 in $VmNames)
{
$VmName = $VmName2.VMName
filter ProcessWMIJob
{
param
(
[WMI]$WmiClass = $null,
[string]$MethodName = $null
)
$errorCode = 0
$returnObject = $_
if ($_.ReturnValue -eq 4096)
{
$Job = [WMI]$_.Job
$returnObject = $Job
while ($Job.JobState -eq 4)
{
Write-Progress -Activity $Job.Caption -Status ($Job.JobStatus + " - " + $Job.PercentComplete + "%") -PercentComplete $Job.PercentComplete
Start-Sleep -seconds 1
$Job.PSBase.Get()
}
if ($Job.JobState -ne 7)
{
if ($Job.ErrorDescription -ne "")
{
Write-Error $Job.ErrorDescription
Throw $Job.ErrorDescription
}
else
{
$errorCode = $Job.ErrorCode
}
}
Write-Progress -Activity $Job.Caption -Status $Job.JobStatus -PercentComplete 100 -Completed:$true
}
elseif($_.ReturnValue -ne 0)
{
$errorCode = $_.ReturnValue
}
if ($errorCode -ne 0)
{
Write-Error "Hyper-V WMI Job Failed!"
if ($WmiClass -and $MethodName)
{
$psWmiClass = [WmiClass]("\\" + $WmiClass.__SERVER + "\" + $WmiClass.__NAMESPACE + ":" + $WmiClass.__CLASS)
$psWmiClass.PSBase.Options.UseAmendedQualifiers = $TRUE
$MethodQualifierValues = ($psWmiClass.PSBase.Methods[$MethodName].Qualifiers)["Values"]
$indexOfError = [System.Array]::IndexOf(($psWmiClass.PSBase.Methods[$MethodName].Qualifiers)["ValueMap"].Value, [string]$errorCode)
if (($indexOfError -ne "-1") -and $MethodQualifierValues)
{
Throw "ReturnCode: ", $errorCode, " ErrorMessage: '", $MethodQualifierValues.Value[$indexOfError], "' - when calling $MethodName"
}
else
{
Throw "ReturnCode: ", $errorCode, " ErrorMessage: 'MessageNotFound' - when calling $MethodName"
}
}
else
{
Throw "ReturnCode: ", $errorCode, "When calling $MethodName - for rich error messages provide classpath and method name."
}
}
return $returnObject
}
# Retrieve an instance of the virtual machine computer system that contains reference points
$Msvm_ComputerSystem = Get-WmiObject -ComputerName $VmName2.ComputerName -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VmName'"
# Retrieve all refrence associations of the virtual machine
$allrefPoints = $Msvm_ComputerSystem.GetRelationships("Msvm_ReferencePointOfVirtualSystem")
# Enumerate across all of the instances and add all recovery points to an array
$virtualSystemRefPoint = @()
$enum = $allrefPoints.GetEnumerator()
$enum.Reset()
while($enum.MoveNext())
{
$Msvm_VirtualSystemReferencePointService = Get-WmiObject -ComputerName $VmName2.ComputerName -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemReferencePointService
# Removes the virtual machine reference, this method returns a job object.
If (([WMI] $enum.Current.Dependent).ElementName -Notlike "_HVR*")
{
$job = $Msvm_VirtualSystemReferencePointService.DestroyReferencePoint([WMI] $enum.Current.Dependent)
# Waits for the job to complete and processes any errors.
$job | ProcessWMIJob -WmiClass $Msvm_VirtualSystemReferencePointService -MethodName "DestroyReferencePoint" | Out-Null
}
}
}
Code: Select all
$VmNames = Get-VM -ComputerName HOST1, HOST2, HOST3, HOST4
Foreach ($VmName2 in $VmNames)
{
$VmName = $VmName2.VMName
# Retrieve an instance of the virtual machine computer system that contains reference points
$Msvm_ComputerSystem = Get-WmiObject -ComputerName $VmName2.ComputerName -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VmName'"
# Retrieve all refrence associations of the virtual machine
$allrefPoints = $Msvm_ComputerSystem.GetRelationships("Msvm_ReferencePointOfVirtualSystem")
# Enumerate across all of the instances and add all recovery points to an array
$virtualSystemRefPoint = @()
$enum = $allrefPoints.GetEnumerator()
$enum.Reset()
while($enum.MoveNext())
{
$virtualSystemRefPoint += ([WMI] $enum.Current.Dependent)
# Removes the virtual machine reference, this method returns a job object.
}
Write-Host $VmName $virtualSystemRefPoint.Count
}
Code: Select all
$VmNames = Get-VM -ComputerName HOST1, HOST2, HOST3, HOST4
Foreach ($VmName2 in $VmNames)
{
$VmName = $VmName2.VMName
# Retrieve an instance of the virtual machine computer system that contains reference points
$Msvm_ComputerSystem = Get-WmiObject -ComputerName $VmName2.ComputerName -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VmName'"
# Retrieve all refrence associations of the virtual machine
$allrefPoints = $Msvm_ComputerSystem.GetRelationships("Msvm_ReferencePointOfVirtualSystem")
# Write the number of refPoints to the console
Write-Host $VmName $allrefPoints.Count
}
Code: Select all
$VmNames = Get-VM -ComputerName XXXX, YYYY, ZZZZ
Foreach ($VmName2 in $VmNames)
{
$VmName = $VmName2.VMName
filter ProcessWMIJob
{
param
(
[WMI]$WmiClass = $null,
[string]$MethodName = $null
)
$errorCode = 0
$returnObject = $_
if ($_.ReturnValue -eq 4096)
{
$Job = [WMI]$_.Job
$returnObject = $Job
while ($Job.JobState -eq 4)
{
Write-Progress -Activity $Job.Caption -Status ($Job.JobStatus + " - " + $Job.PercentComplete + "%") -PercentComplete $Job.PercentComplete
Start-Sleep -seconds 1
$Job.PSBase.Get()
}
if ($Job.JobState -ne 7)
{
if ($Job.ErrorDescription -ne "")
{
Write-Error $Job.ErrorDescription
Throw $Job.ErrorDescription
}
else
{
$errorCode = $Job.ErrorCode
}
}
Write-Progress -Activity $Job.Caption -Status $Job.JobStatus -PercentComplete 100 -Completed:$true
}
elseif($_.ReturnValue -ne 0)
{
$errorCode = $_.ReturnValue
}
if ($errorCode -ne 0)
{
Write-Error "Hyper-V WMI Job Failed!"
if ($WmiClass -and $MethodName)
{
$psWmiClass = [WmiClass]("\\" + $WmiClass.__SERVER + "\" + $WmiClass.__NAMESPACE + ":" + $WmiClass.__CLASS)
$psWmiClass.PSBase.Options.UseAmendedQualifiers = $TRUE
$MethodQualifierValues = ($psWmiClass.PSBase.Methods[$MethodName].Qualifiers)["Values"]
$indexOfError = [System.Array]::IndexOf(($psWmiClass.PSBase.Methods[$MethodName].Qualifiers)["ValueMap"].Value, [string]$errorCode)
if (($indexOfError -ne "-1") -and $MethodQualifierValues)
{
Throw "ReturnCode: ", $errorCode, " ErrorMessage: '", $MethodQualifierValues.Value[$indexOfError], "' - when calling $MethodName"
}
else
{
Throw "ReturnCode: ", $errorCode, " ErrorMessage: 'MessageNotFound' - when calling $MethodName"
}
}
else
{
Throw "ReturnCode: ", $errorCode, "When calling $MethodName - for rich error messages provide classpath and method name."
}
}
return $returnObject
}
# Retrieve an instance of the virtual machine computer system that contains reference points
$Msvm_ComputerSystem = Get-WmiObject -ComputerName $VmName2.ComputerName -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VmName'"
# Retrieve all refrence associations of the virtual machine
$allrefPoints = $Msvm_ComputerSystem.GetRelationships("Msvm_ReferencePointOfVirtualSystem")
# Enumerate across all of the instances and add all recovery points to an array
$virtualSystemRefPoint = @()
$enum = $allrefPoints.GetEnumerator()
$enum.Reset()
while($enum.MoveNext())
{
$name = ([WMI]$enum.Current.Dependent).ElementName
# Skip Hyper-V Replica Reference points
If ($name -Notlike "_HVR*")
{
$regex = [regex]"\((.*)\)"
$date = [DateTime]::Parse([regex]::match($name, $regex).Groups[1].ToString().Replace(" - "," "))
$timespan = New-TimeSpan -End $date
# Keep any reference points from the last 7 days
if($timespan.TotalDays -lt -7)
{
Write-Host "Deleting " $name $timespan -ForegroundColor Yellow
$Msvm_VirtualSystemReferencePointService = Get-WmiObject -ComputerName $VmName2.ComputerName -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemReferencePointService
# Removes the virtual machine reference, this method returns a job object.
$job = $Msvm_VirtualSystemReferencePointService.DestroyReferencePoint([WMI] $enum.Current.Dependent)
# Waits for the job to complete and processes any errors.
$job | ProcessWMIJob -WmiClass $Msvm_VirtualSystemReferencePointService -MethodName "DestroyReferencePoint" | Out-Null
}
else
{
Write-Host "Skipping " $name $time -ForegroundColor Green
}
}
}
}
For virtual machines running in a Windows Server 2016 Hyper-V cluster, the use of checkpoints for backups simplifies the backup process. For each virtual machine, the backup takes a checkpoint that includes only that virtual machine. Once the backup is completed, the checkpoint is converted to a reference point with a unique ID and saved with the backup. Changed block tracking uses the reference point to identify changes since the last backup. The reference point is retained until the next backup is completed and a new checkpoint is generated.
Users browsing this forum: No registered users and 13 guests