PowershellGuru
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login
No Result
View All Result
PowershellGuru
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login
No Result
View All Result
PowershellGuru
No Result
View All Result
Home Powershell Script blogs

How to find NTP Server using PowerShell?

themeanmachine19@gmail.com by [email protected]
November 27, 2021
in Powershell Script blogs
0
How to find NTP Server using PowerShell?
Share on FacebookShare on Twitter

You might also like

Instant guide to convert ps2 to exe

Instant Guide To Convert PS1 To EXE (2022)

May 21, 2022
PowerShell tips and tricks

5 Useful PowerShell Tips and Tricks

May 15, 2022

Hello, PowerShell enthusiast today I will be sharing a script to fetch the NTP (Network Time Protocol) server name from remote servers using our favourite PowerShell. We as windows admin know that a Primary Domain controller holds the NTP role. If you are not aware of the term then let’s understand what is NTP before proceeding ahead.

How to find NTP Server using PowerShell?

What is NTP server and how to check it?

The default time synchronization protocol used by the Windows Time service in the operating system is Network Time Protocol (NTP). NTP is a fault-tolerant, highly scalable time protocol that is most commonly used to synchronize computer clocks using a known time reference.

You can check the NTP source by using the below command on the server or your personal computers as well in the command prompt or in PowerShell. If the command gives Local CMOS clock as an output then your server/system is taking time from the CMOS battery or the ESXI. If the output is any time source then it might be taken from the internet or some specified NTP source.

				
					w32tm /query /source
				
			

Finding NTP server using PowerShell

Step #1 

New-Object System.Collections.ArrayList is used to collect data and unlike array it is not fixed and of 
course,we have a Foreach loop to loop through the provided list of the server.
				
					$Inventory = New-Object System.Collections.ArrayList
$AllComputers = gc C:\users\admin\desktop\server.txt
foreach($computers in $allcomputers){
$Computers
				
			

Step #2

 $ComputerInfo will create a new object of system object ( It is being used to dump the output to CSV file).

 

$ntp this is our main command, it will search for the source on each of the mentioned servers provided in the list.

				
					$ComputerInfo = New-Object System.Object
$ntp = w32tm /query /computer:$computers /source

				
			

Step #3

Here the type ServerName is filled with the values of $computers and type NTP Source is filled with $ntp values. Each of them is stored into $computerinfo.

 

				
					$ComputerInfo |Add-Member -MemberType NoteProperty -Name "ServerName" -Value "$Computers" 

$ComputerInfo |Add-Member -MemberType NoteProperty -Name "NTP Source" -Value "$Ntp" 

				
			

Step #4

All the values stored in $ComputerInfo are added to $Inventory.

 

Out-Null is being used to give no output on the screen.

 

				
					$Inventory.Add($ComputerInfo) | Out-Null
  }

$Inventory | Export-Csv C:\users\admin\desktop\NTP.csv -NoTypeInformation
				
			

Result of the PowerShell script

Below is the result of the script in the CSV format.

 

ServerNameNTP Source
MY-PCtime.windows.com,0x9 
test-server1dc.test.com
test-server2dc.test.com

 

Conclusion

I hope you have liked the post How to find NTP Server using PowerShell? and will implement this whenever it is required. Things you should always remember is to try with one server so that it will be easy for you to make changes. Let me know if you want a blog post on some other script that might amaze you.

We are working continuously to provide you with the better and the best scripts daily. We will publish weekly hence don’t forget to subscribe to our newsletter. 

Please login to join discussion
close

DON’T MISS A POST

Keep up to date with PowershellGuru

Powershell Blogs

PowershellGuru provides the best PowerShell scripts available that can be used and download freely. Do Check our blogs to get updated regularly.

Check your inbox or spam folder to confirm your subscription.

themeanmachine19@gmail.com

[email protected]

Related Stories

Instant guide to convert ps2 to exe

Instant Guide To Convert PS1 To EXE (2022)

by [email protected]
May 21, 2022
0

Instant guide to convert ps1 to exe. How to convert ps1 to exe. PS2exe. Convert ps1 to exe using ps2exe.

PowerShell tips and tricks

5 Useful PowerShell Tips and Tricks

by [email protected]
May 15, 2022
0

Useful Powershell tips and tricks. PowerShell tips and tricks. Know Powershell tips and tricks. get-help. get-alias.

tips to manage hyper-v using powershell

5 Tips To Manage Hyper-V Using PowerShell

by [email protected]
May 1, 2022
0

Tips to manage hyper-v using PowerShell. How to manage Hyper-V using PowerShell. Powershell to manage Hyper-V. Hyper-v and PowerShell.

Mistakes To Avoid While Writing A Powershell Script

5 Big Mistakes To Avoid While Writing A Powershell Script

by [email protected]
April 30, 2022
0

Mistakes to avoid while writing a powershell script. PowerShell mistakes. Avoid these mistakes in a powershell script. PowershellGuru.

Next Post
How to easily manage DNS Zone using PowerShell?

How to easily manage DNS Zone using PowerShell?

Please login to join discussion

Recommended

Mirroring two AD groups using PowerShell

Mirroring two AD groups using PowerShell (Fast)

December 14, 2021
Configuring Pagefile using GUI and PowerShell

Configuring Pagefile using GUI and PowerShell (2021)

October 9, 2021

About

Dhrub Bharali

PowerShell Enthusiast

Dhrub is hardcore Powershell enthusiast, he has wriiten more than 100 powershell scripts and he is the sole owner of PowerShellGuru.

Follow Us

Popular Story

  • Installing software remotely using powershell

    Easy way to install software remotely using PowerShell (2021)

    827 shares
    Share 331 Tweet 207
  • Detect Log4j vulnerable servers using PowerShell

    753 shares
    Share 301 Tweet 188
  • How to find NTP Server using PowerShell?

    738 shares
    Share 295 Tweet 185
  • Get-LocalGroupMember: Find Local admin using PowerShell (2021)

    728 shares
    Share 291 Tweet 182
  • Get installed software list quickly using PowerShell (2021)

    695 shares
    Share 278 Tweet 174
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login

© 2022 PowershellGuru- PowerShell Scripts For Automation

No Result
View All Result
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login

© 2022 PowershellGuru- PowerShell Scripts For Automation

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.