Hi, where is the problem?
My Code:
Param ( [String]$hvHost ) set-item wsman:\localhost\Client\TrustedHosts -value $hvHost -Force $password = ConvertTo-SecureString "xxxxx" -AsPlainText -Force $user = "LAIAUTO\support" $cred = New-Object System.Management.Automation.PSCredential ($user,$password) $s = New-PSSession -ComputerName $hvHost -Credential $cred Invoke-Command -Session $s{ # ----------------------- $CurrentDate = (Get-Date) $Results = Get-VMReplication | Select VMName, VMId, ReplicationMode, ReplicationHealth, ComputerName,` PrimaryServer, ReplicaServer, LastReplicationTime, ReplicationState ` | Where-Object ReplicationMode -eq "Primary" $xmlstring = "<?xml version=`"1.0`"?>`n <prtg>`n" ForEach ($eachresult IN $Results) { $TotalMinutes = (New-Timespan –Start $eachresult.LastReplicationTime –End $CurrentDate).TotalMinutes $xmlstring += " <result>`n" $xmlstring += " <channel>$($eachresult.VMname)</channel>`n" $xmlstring += " <unit>Custom</unit>`n" $xmlstring += " <CustomUnit>min</CustomUnit>`n" $xmlstring += " <mode>Absolute</mode>`n" $xmlstring += " <showChart>1</showChart>`n" $xmlstring += " <showTable>1</showTable>`n" $xmlstring += " <float>0</float>`n" $xmlstring += " <value>$(IF ($TotalMinutes -lt 1) {"0"} ELSE {IF ($TotalMinutes -le 60) {$TotalMinutes.ToString("#")} ELSE {"60"}})</value>`n" $xmlstring += " <LimitMaxError>59</LimitMaxError>`n" $xmlstring += " <LimitMaxWarning>20</LimitMaxWarning>`n" $xmlstring += " <LimitWarningMsg>Hyper-V Replication for this VM is in Warning state</LimitWarningMsg>`n" $xmlstring += " <LimitErrorMsg>Hyper-V Replication failed for this VM and is in Critical state</LimitErrorMsg>`n" $xmlstring += " <LimitMode>1</LimitMode>`n" $xmlstring += " </result>`n" } $xmlstring += " </prtg>" Write-Host $xmlstring } If I run this on PS console work fine PS C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML> .\Replica.ps1 -hvHost 10.55.55.137 <?xml version="1.0"?> <prtg> <result> <channel>VM2019OR-01 (SALONE)</channel> <unit>Custom</unit> <CustomUnit>min</CustomUnit> <mode>Absolute</mode> <showChart>1</showChart> <showTable>1</showTable> <float>0</float> <value>2</value> <LimitMaxError>59</LimitMaxError> <LimitMaxWarning>20</LimitMaxWarning> <LimitWarningMsg>Hyper-V Replication for this VM is in Warning state</LimitWarningMsg> <LimitErrorMsg>Hyper-V Replication failed for this VM and is in Critical state</LimitErrorMsg> <LimitMode>1</LimitMode> </result> </prtg>
But my PRTG server send me error
Sensor
XML Custom EXE/Script Sensor
XML: The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (No mapping for the Unicode character exists in the target multi-byte code page). (code: PE231)
And log file is:
A command that prompts the user for information failed because the host program or command type does not support user interactions. Try a host program that supports such interactions, such as the Windows PowerShell console or Windows PowerShell ISE, and remove prompt-related commands from command types that don't support user interactions, such as Windows PowerShell workflows.
Whre is the problem????? Ty
Add comment