Solved

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

Posted on 2015-02-10
8
249 Views
Last Modified: 2015-02-12
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.
0
Comment
8 Comments
 
LVL 17

Assisted Solution

by:Learnctx
Learnctx earned 50 total points
ID: 40602360
Edit: Sorry I've just realised you're using Get-DomainController and not Get-ADDomainController. Why not use the AD cmdlet instead of the Exchange cmdlet? Surely the Exchange server would have this cmdlet available?

I've edited the below for Get-ADDomainController instead of Get-DomainController.

Import-Module ActiveDirectory
$DomainControllers = Get-ADDomainController -Filter *

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

$DomainNTPStatus

Open in new window

0
 
LVL 7

Author Comment

by:Senior IT System Engineer
ID: 40602373
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,,

0
 
LVL 7

Author Comment

by:Senior IT System Engineer
ID: 40602377
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.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 14

Assisted Solution

by:frankhelk
frankhelk earned 50 total points
ID: 40603148
Even while it's a bit off topic ... such woes are one reason for me to avoid W32time whenever I can.

My recommendation:

Use a Windows port of the classic *ix NTP service on your servers. The status could be retrieved remote with a single command (ntpq -p <ip/name>) and the configuration is a very simple plaintext file. The NTP service software is free. Easy to install and configure, works like a charm and is stable as a rock. And it is nicer when it comes to one of the rare cases of troubleshooting.

See this article for the "How To".

The NTP service has a low ressource footprint, therefore the NTP functionality could be hooked onto existing machines or VM's like webservers, ftp servers, mailservers or database hosts - even in a DMZ - without visible performance impact.

If securtity is an issue, you might as well place radio controlled clock appliances into your LAN who serve time very reliable and precise.
0
 
LVL 39

Accepted Solution

by:
footech earned 400 total points
ID: 40606362
Corrected version of LearnCTX's.  But if you don't have the AD module you'll have to let us know.
Import-Module ActiveDirectory
$DomainControllers = Get-ADDomainController -Filter * | Select -expand Name

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

0
 
LVL 7

Author Comment

by:Senior IT System Engineer
ID: 40606738
Do i have to execute the command above in the domain controller or can I run it on my laptop running with PowerGUI ?
0
 
LVL 39

Expert Comment

by:footech
ID: 40606897
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).
0
 
LVL 7

Author Closing Comment

by:Senior IT System Engineer
ID: 40606992
Thanks, it works.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
A brief introduction to what I consider to be the best editor for PowerShell.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question