Link to home
Start Free TrialLog in
Avatar of Albert Widjaja
Albert WidjajaFlag for Australia

asked on

need some help in modifying Powershell script to get the NTP status for all domain controllers

Hi,

Can anyone here please assist me in how to get the NTP configuration setting for all domain controllers uisng Powershell below ?

$DomainControllers = Get-DomainController

Write-Verbose "Check Domain Time Configuration `r"
ForEach ($DC in $DomainControllers) { 
	$ADTimeCheck = w32tm /monitor /computers:$DC
	$ADTimeCheck1 = $ADTimeCheck -split ("ICMP: ")
	$ADTimeCheck2 = $ADTimeCheck1 -split ("NTP: ")
	$ADTimeCheck3 = $ADTimeCheck2 -split ("RefID: ")
	$ADTimeCheckICMP = $ADTimeCheck3[13]
	$ADTimeCheckNTP = $ADTimeCheck3[15]
	[array]$DomainNTPStatus += "$DC,$ADTimeCheckICMP,$ADTimeCheckNTP"
}

$DomainNTPStatus

Open in new window


because when I use the Powershell script above, it failed with no result.

Note: the Get-DomainController cmdlet is from the Exchange Server 2010 powershell.

Thanks in advance.
SOLUTION
Avatar of Aard Vark
Aard Vark
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Albert Widjaja

ASKER

Thanks for the quick reply, but somehow i got the following weird result:

,,
domain.com/Configuration/Sites/HQ/Servers/HQDC01,,
domain.com/Configuration/Sites/DataCentre/Servers/DCDC01,,
domain.com/Configuration/Sites/DataCentre/Servers/DCDC02,,
domain.com/Configuration/Sites/DataCentre/Servers/DCDC03,,
domain.com/Configuration/Sites/Branch1/Servers/BRANCH2012DC01,,
Microsoft.ActiveDirectory.Management.ADDomainController.Name,,
Microsoft.ActiveDirectory.Management.ADDomainController.Name,,
Microsoft.ActiveDirectory.Management.ADDomainController.Name,,
Microsoft.ActiveDirectory.Management.ADDomainController.Name,,
Microsoft.ActiveDirectory.Management.ADDomainController.Name,,

This is the value of the variable:

$ADTimeCheck

{Analyzing Microsoft.ActiveDirectory.Management.ADDomainController.Name (1 of 1)..., error WSAHOST_NOT_FOUND], ,  ,  , Microsoft.ActiveDirectory.Management.ADDomainController.Name [}

Do I have to run it from the Domain Controller or it can be executed from my laptop using the PowerGUI script editor ?

all of the hosts from the previous result are online and ping-able.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do i have to execute the command above in the domain controller or can I run it on my laptop running with PowerGUI ?
You can run it on a workstation if it has RSAT tools installed so that the ActiveDirectory module is available.  Otherwise, it would have to be done from a domain controller (assuming Server 2008 R2 or newer).
Thanks, it works.