Share via


How to get the NTP server value from powershell for all of the non domain joined server ?

Question

Monday, September 5, 2011 5:24 AM

Hi All,

I got mixed environment of Windows Server 2003 and 2008 that is joined to the domain and some of them not joined to the domain, how is it possible to get the TIme server value from this server using Powershell ? /* Server Support Specialist */

All replies (9)

Monday, September 5, 2011 5:39 AM ✅Answered | 4 votes

Try this Powershell script (save it as .ps1):

 

$servers = @('server01','server02')

foreach ($server in $servers){
$ntps = w32tm /query /computer:$server /configuration | ?{$_ -match 'ntpserver:'} | %{($_ -split ":\s\b")[1]}
new-object psobject -property @{
    Server = $Server
    NTPSource = $ntps
    }
}

Make sure to run the script with an account that has permissions on the servers and in an elevated session.

 

If you found this post helpful, please "Vote as Helpful". If it answered your question, remember to "Mark as Answer".

Rich Prescott | MCITP, MCTS, MCP

[Blog] Engineering Efficiency | [Twitter] @Rich_Prescott | [Powershell GUI] Client System Administration toolkit


Tuesday, September 6, 2011 3:17 AM ✅Answered | 1 vote

Powershell does not need to be installed on anything but the machine the script is run from.  The only requirements are the two items I listed above.

  1. Elevated rights for the script
  2. Administrative permissions to the machines you want to pull the information from

If you found this post helpful, please "Vote as Helpful". If it answered your question, remember to "Mark as Answer".

Rich Prescott | MCITP, MCTS, MCP

[Blog] Engineering Efficiency | [Twitter] @Rich_Prescott | [Powershell GUI] Client System Administration toolkit


Monday, September 5, 2011 6:03 AM

Thanks for the reply, however as some of the server is not joined to the domain, so my current username which is member of the DOMAIN\Administrators doesn't seems to work :-|/* Server Support Specialist */


Monday, September 5, 2011 6:08 AM

Shift-right-click on Powershell.exe and select Run as another user...If you found this post helpful, please "Vote as Helpful". If it answered your question, remember to "Mark as Answer".

Rich Prescott | MCITP, MCTS, MCP

[Blog] Engineering Efficiency | [Twitter] @Rich_Prescott | [Powershell GUI] Client System Administration toolkit


Tuesday, September 6, 2011 2:44 AM | 1 vote

Hi Albert,

 

Thanks for posting here.

 

We should also ensure that the WinRM service had been started and also make sure these hosts have been added to the TrustedHosts configuration settings before we remotely perform powershell commands on non-domain joined hosts . For more detail information please refer to the article below :

 

Enable and Use Remote Commands in Windows PowerShell

http://technet.microsoft.com/en-us/magazine/ff700227.aspx

 

Regards,

 

Tiger Li

 

TechNet Subscriber Support in forum

If you have any feedback on our support, please contact  [email protected]

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.


Tuesday, September 6, 2011 2:49 AM

Hi Li,

Does this also could possibly the cause that the script above failed ?

I got some Windows Server 2003 in that zone which doesn't have powershell v1 installed.

/* Server Support Specialist */


Tuesday, September 6, 2011 3:19 AM | 1 vote

Hi Albert,

 

Thanks for posting here.

 

We should also ensure that the WinRM service had been started and also make sure these hosts have been added to the TrustedHosts configuration settings before we remotely perform powershell commands on non-domain joined hosts . For more detail information please refer to the article below :

 

Enable and Use Remote Commands in Windows PowerShell

http://technet.microsoft.com/en-us/magazine/ff700227.aspx

 

Regards,

 

Tiger Li

 

TechNet Subscriber Support in forum

If you have any feedback on our support, please contact  [email protected]

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

That is not necessary.  I am using w32tm to query the information remotely and then using Powershell to parse the information into an object that is output.  If he is able to run the following query and receive results, the script should work as well.

w32tm /query /computer:<server> /configuration

If you found this post helpful, please "Vote as Helpful". If it answered your question, remember to "Mark as Answer".

Rich Prescott | MCITP, MCTS, MCP

[Blog] Engineering Efficiency | [Twitter] @Rich_Prescott | [Powershell GUI] Client System Administration toolkit


Wednesday, September 7, 2011 2:38 AM | 3 votes

Even better script.  Don't know how I missed that option.

$servers = @('server01','server02')

foreach ($server in $servers){
$ntps = w32tm /query /computer:$server /source
new-object psobject -property @{
    Server = $Server
    NTPSource = $ntps
    }
}

If you found this post helpful, please "Vote as Helpful". If it answered your question, remember to "Mark as Answer".

Rich Prescott | MCITP, MCTS, MCP

[Blog] Engineering Efficiency | [Twitter] @Rich_Prescott | [Powershell GUI] Client System Administration toolkit


Sunday, October 29, 2017 9:46 AM

The script is executing successfully without any errors but in "NTPSource" output column i am getting blank data. In the client servers i checked ,the NTP is pointing to "time.windows.com". Can you help me with this query.