---
updatedAt: 2025-08-14T13:53:52.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-sight/llms.txt
---

# Monitor Hyper-V Replica

```powershell PowerShell
OPTION EXPLICIT
' getHVRstate.vbs
' purpose: return Hyper-V Replica state for monitoring purposes
' author: Rob Eberhardt
' versions: 2013-04-30  first
'			2013-05-10	now checks for "critical" and "warning" too
'			2015-01-05	rewrite for better reporting
'			2015-02-03	suppress alerts on ExtendedReplica Warnings (local warnings still alert)
' ref: http://deploymentbunny.com/2013/01/16/powershell-is-kingdoes-my-vms-replicate-correct-i-need-a-report/

DIM strPScheck
'strPScheck = "powershell Get-VMReplication |ft Name, State, Health, Mode"
' use custom format so we can indent without wrapping:
strPScheck = "powershell Get-VMReplication |ft " & _
	"@{Expression={$_.Name};	Label='Name'; 	width=24}, " & _
	"@{Expression={$_.State}; Label='State'; 	width=28}, " & _
	"@{Expression={$_.Health};Label='Health'; width=9}, " & _
	"@{Expression={$_.Mode}; 	Label='Mode'; 	width=16}"
	

DIM objShell, objExecObject, strText
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec(strPScheck)

DIM bStart, bAlert
bStart = false
bAlert = false
Do While Not objExecObject.StdOut.AtEndOfStream
    'strText = strText & vbCRLF & objExecObject.StdOut.ReadLine()
	DIM strLine, arrLine, strErrorRpt, strFullRpt
	strLine = objExecObject.StdOut.ReadLine()
	strFullRpt = strFullRpt & vbCRLF & "  " & strLine
	'call WScript.Echo(strLine)

	'cleanup formatting & make into an array
	strLine = trimInternal(strLine)
	arrLine = split(strLine, " ")	'0=Name, 1=State, 2=Health, 3=Mode
	IF bStart AND ubound(arrLine)>0 THEN
		SELECT CASE arrLine(2)
			CASE "Error"
				strErrorRpt = strErrorRpt & _
					"  " & arrLine(0) & " = " & arrLine(2) & vbCRLF 
				bAlert = true
			CASE "Critical"
				strErrorRpt = strErrorRpt & _
					"  " & arrLine(0) & " = " & arrLine(2) & vbCRLF 
				bAlert = true
			CASE "Warning"
				strErrorRpt = strErrorRpt & _
					"  " & arrLine(0) & " = " & arrLine(2) & vbCRLF 
				IF arrLine(3)<>"ExtendedReplica" THEN bAlert = true	'only alert Warnings for local
		END SELECT
	END IF
	IF Left(strLine, 4) = "----" THEN bStart = true	' ignore until first row of data
Loop
strFullRpt = Mid(strFullRpt, 7, 10000) ' remove initial linebreaks


'IF strErrorRpt<>"" Then
IF bAlert THEN
	call WScript.Echo("PROBLEMS!" & vbCRLF & strErrorRpt)
	call WScript.Echo("FULL REPORT:" & vbCRLF & strFullRpt)
	call Wscript.Quit(1000)
Else
	call WScript.Echo("ALL OK!" & vbCRLF)
	call WScript.Echo("FULL REPORT:" & vbCRLF & strFullRpt)
	call Wscript.Quit(0)
END IF


'like Trim, but also handles internal whitespace
FUNCTION trimInternal(p_str)
	DIM RegEx
	Set RegEx = New RegExp
	Regex.global = true
	Regex.pattern = " +( |$)"
	trimInternal = Regex.Replace(p_str, "$1")
END FUNCTION

```

```json Response Example
{"success":true}
```

# SCRIPT





# trimInternal

<!-- powershell@72-78 -->