Hello, Below is a script I wrote to check the a server is using the correct NTP server. I checked the output in a regular Powershell session (using Version 2) and I can't spot any problems with the output. Additionally I have the 'Run the script under specified account` checked and have tested this with the specified user.
$expectedNtpServer = $args.Get(0).ToLower().Trim()
$serverToCheck = $args.Get(1)
$currentNtpServer = (w32tm /query /source /computer:$serverToCheck).ToLower().Trim()
if($currentNtpServer -match '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b') {
$currentNtpServer = [System.Net.Dns]::gethostentry($ip).HostName.ToLower().Trim()
}
if($currentNtpServer -ne $expectedNtpServer) {
Write-Host "Message.Status: $serverToCheck is using a different NTP Server than expected. Actual $currentNtpServer Expected $expectedNtpServer"
Write-Host "Statistic.Status: 0"
exit 3
}
Write-Host "Message.Status: $serverToCheck is using the expected NTP Server: $expectedNtpServer"
Write-Host "Statistic.Status: 0"
exit 0
Here is the output I get when I run it in Powershell:
PS> .\NTPSourceChecker.ps1 DC1.domain.com DC2.domain.com
Message.Status: DC2 is using a different NTP Server than expected. Actual: DC3.domain.com Expected: DC1.domain.com
Statistic.Status: 0
Any thoughts on why I can't get the ouptut to work in the application monitor template?