Tag Archives: Hyper-V

How to monitor Hyper-V Replica Health with the custom advanced Sensor in Paessler PRTG

With this VBS Script you can Monitor Hyper-V Replica Health with the custom Advanced XML Sensor in Paessler PRTG.
https://prtg.paessler.com/api.htm?tabid=7
Replace server.domain.local with IP or DNS Name of your Hyper-V Server.
The PRTG Service Account needs to have Admin rights on Hyper-V Host (SYSTEM uses AD Computer Account to access remote Servers).
Save the VBS in “C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML” Folder.
Create a Custom EXE/Script Advanced Sensor and select the Script.
You have to install the Windows Management Framework 3.0 .

locstrServer = "server.domain.local"
locstrText = ""
locstrStatus = ""
set objWshShell = CreateObject("WScript.Shell")
wscript.echo "<?xml version=""1.0"" encoding=""Windows-1252"" ?>"
wscript.echo "<prtg>"
locstrCommand = "cmd /c powershell.exe Invoke-Command -ComputerName " & locstrServer & " -ScriptBlock { Get-VMReplication ^| where Health -eq 'Normal' ^| measure-object }"
Set locobjExec = objWshShell.Exec(locstrCommand)
Do While Not locobjExec.StdOut.AtEndOfStream
 locstrReadline = trim(locobjExec.StdOut.ReadLine())
 locstrReadline = replace(locstrReadline, " ", "")
 if left(lcase(locstrReadline), len("count:")) = "count:" then 
  wscript.echo "<result>"
  wscript.echo "<channel>Health Normal Count</channel>"
  locintcount = cint(replace(lcase(locstrReadline), "count:", ""))  
  wscript.echo "<value>" & locintcount & "</value>"
  wscript.echo "<unit>Count</unit>"  
  wscript.echo "</result>"
 end if
Loop
locstrCommand = "cmd /c powershell.exe Invoke-Command -ComputerName " & locstrServer & " -ScriptBlock { Get-VMReplication ^| where Health -eq 'Warning' ^| measure-object }"
Set locobjExec = objWshShell.Exec(locstrCommand)
Do While Not locobjExec.StdOut.AtEndOfStream
 locstrReadline = trim(locobjExec.StdOut.ReadLine())
 locstrReadline = replace(locstrReadline, " ", "")
 if left(lcase(locstrReadline), len("count:")) = "count:" then 
  wscript.echo "<result>"
  wscript.echo "<LimitMaxWarning>0</LimitMaxWarning>"
  wscript.echo "<LimitMode>1</LimitMode>"
  wscript.echo "<channel>Health Warning Count</channel>"
  locintcount = cint(replace(lcase(locstrReadline), "count:", ""))
  wscript.echo "<LimitWarningMsg>Hyper-V Replica(s) Health Warning!</LimitWarningMsg>"
  wscript.echo "<value>" & locintcount & "</value>"
  wscript.echo "<unit>Count</unit>"
  wscript.echo "</result>"
 end if
Loop
locstrCommand = "cmd /c powershell.exe Invoke-Command -ComputerName " & locstrServer & " -ScriptBlock { Get-VMReplication ^| where Health -eq 'Critical' ^| measure-object }"
Set locobjExec = objWshShell.Exec(locstrCommand)
Do While Not locobjExec.StdOut.AtEndOfStream
 locstrReadline = trim(locobjExec.StdOut.ReadLine())
 locstrReadline = replace(locstrReadline, " ", "")
 if left(lcase(locstrReadline), len("count:")) = "count:" then 
  wscript.echo "<result>"
  wscript.echo "<LimitMaxError>0</LimitMaxError>"
  wscript.echo "<LimitMode>1</LimitMode>"  
  wscript.echo "<channel>Health Critical Count</channel>"
  locintcount = cint(replace(lcase(locstrReadline), "count:", ""))  
  wscript.echo "<LimitErrorMsg>Hyper-V Replica(s) Health Critical!</LimitErrorMsg>"
  wscript.echo "<value>" & locintcount & "</value>"
  wscript.echo "<unit>Count</unit>"  
  wscript.echo "</result>"
 end if
Loop
if locstrStatus <> "" then wscript.echo locstrStatus
if locstrText <> "" then wscript.echo locstrText
wscript.echo "</prtg>"

How to monitor Hyper-V Replica Health with Paessler PRTG

With this quick and dirty VBS Script you can Monitor Hyper-V Replica Health with Peassler PRTG.
Replace server.domain.local with IP or DNS Name of your Hyper-V Server.
The PRTG Service Account needs to have Admin rights on Hyper-V Host (SYSTEM uses AD Computer Account to access remote Servers).
Save the VBS in “C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE” Folder.
Create a Custom EXE/Script Sensor and select the Script.
You have to install the Windows Management Framework 3.0 .

set objWshShell = CreateObject("WScript.Shell")

locstrCommand = "cmd /c powershell.exe Invoke-Command -ComputerName server.domain.local -ScriptBlock { Get-VMReplication ^| where Health -ne 'Normal' ^| measure-object }"

Set locobjExec = objWshShell.Exec(locstrCommand)

Do While Not locobjExec.StdOut.AtEndOfStream
 locstrReadline = trim(locobjExec.StdOut.ReadLine())
 locstrReadline = replace(locstrReadline, " ", "")
 wscript.echo locstrReadline
 if left(lcase(locstrReadline), len("count:0")) = "count:0" then 
  wscript.echo "0:Ok"
  wscript.quit 0
 end if
Loop

wscript.echo "2:One or more Hyper-V Replicas are different from Normal!"
wscript.quit 2

Powershell Script to Move all Hyper-V VM Replicas to another Hyper-V Host

Powershell Script to Move all Hyper-V VM Replicas to another Hyper-V Host

Scenario:
Hyper-V Server 2012 R2 Cluster CLUSTERNAME.domain.local
Hyper-V Server 2012 R2 Replica Server server1.domain.local and server2.domain.local

This Script suspends the replica, moves the replica VM from server1.domain.local to server2.domain.local (D:\Hyper-V\), sets the new Replica Server and resumes replica for all replicas on server1.domain.local:

$ReplicaServerOld="server1.domain.local"
$ReplicaServerNew="server2.domain.local"
ForEach ($VMReplication in (Get-VMReplication -ComputerName (Get-Cluster -Name CLUSTERNAME.domain.local | Get-ClusterNode) | Where-Object {$_.ReplicaServer -like $ReplicaServerOld}))
{
	$VMPrimary = get-vm $VMReplication.Name -ComputerName $VMReplication.PrimaryServerName
	$VMReplica = get-vm $VMReplication.Name -ComputerName $VMReplication.ReplicaServerName
	$VMPrimary | Suspend-VMReplication
	Move-VM $VMReplica.Name -DestinationHost $ReplicaServerNew -IncludeStorage -DestinationStoragePath ("D:\Hyper-V\" + $VMReplica.Name)
	$VMPrimary | Set-VMReplication -ReplicaServerName $ReplicaServerNew
	$VMPrimary | Resume-VMReplication
}

You must configure Kerberos Constrained Delegation for Hyper-V Management or run the script on server1.domain.local
No error handling at the moment…

PowerShell Script to Export the newest VSS Consistent Snapshot from the Hyper-V Replica server

PowerShell Script to Export the last VSS Consistent Snapshot from the Hyper-V Replica server

Scenario:
Hyper-V Server 2012 R2 Cluster CLUSTERNAME with a Primary Server of the VM “VMNAME”
Hyper-V Server 2012 R2 Replica Server with a Replica of the VM “VMNAME”
Hyper-V Replica with VSS Consistent Snapshots History

How can i Export the newest VSS Consistent Snapshot from the Hyper-V Replica Server in order to avoid Backup/Export IO on the Primary Servers Storage?

$VM = "VMNAME"
$ReplicaHOST = Get-Cluster CLUSTERNAME | Get-ClusterResource ("Virtual Machine Configuration " + $VM) | Get-VM | Get-VMReplication | Select-Object -ExpandProperty ReplicaServer
Get-VMSnapshot -ComputerName $ReplicaHOST -VMName $VM -SnapshotType AppConsistentReplica | Sort-Object CreationTime -descending | Select-Object -first 1 | Start-VMFailover -AsTest -Confirm:$false
Get-VM -ComputerName $ReplicaHOST ($VM + " - Test") | Export-VM -Path "d:\

Add a line to clean up the Test Failover VM
You have a VSS Consistent/Ready to Import VM
Unfortunately there is a differential disk AVHD(X) File you have to merge