- <#
- .SYNOPSIS
- Gets the SNTP servers a machine is configured to use
- .DESCRIPTION
- Gets the SNTP servers a machine is configured to use
- .PARAMETER Server
- The machine to get the SNTP Servers for
- .EXAMPLE
- PS C:\> Get-SNTPServer -Server MachineName
- This is return the SNTP servers for MachienName
- .EXAMPLE
- PS C:\> Get-SNTPServer -server Machine1 | Set-SNTPServer -server Machine2
- This will get the sntp server for Machine1 and set Machine2 to the same
- .EXAMPLE
- PS C:\> Get-Content servers.txt | Get-SNTPServer
- .NOTES
- NAME : Get-SNTPServer
- VERSION : 1.0
- LAST UPDATED: 04/04/2011
- AUTHOR : a Monkey
- .LINK
- http://amonkeysden.tumblr.com/post/4393059808/sntp-module
- #>
- function Get-SNTPServer
- {
- [cmdletbinding()]
- Param(
- [Parameter(
- Mandatory = $True,
- Position = 0,
- ParameterSetName = '',
- ValueFromPipeline = $True)]
- [string]$Server
- )
- [string] $z = net time \\$server /QUERYSNTP
- if (($z.contains("The current SNTP value is:"))) {
- #$out = "{0}: {1}" -f $Server,$z.split(" ")[5]
- #Write-Output $out
- Write-Output $z.split(" ")[5]
- } else {
- Write-Error "$z"
- }
- }
- <#
- .SYNOPSIS
- Sets the SNTP servers a machine is configured to use
- .DESCRIPTION
- Sets the SNTP servers a machine is configured to use
- .PARAMETER Servers
- The machines to set the SNTP Servers for
- .PARAMETER $SNTPServerList
- The machine to get the SNTP Servers for
- .EXAMPLE
- PS C:\> Set-SNTPServer -Server MachineName -SNTPServerList "dc1,dc2"
- This will set the SNTP servers to DC1 and DC2 for MachienName
- .EXAMPLE
- PS C:\> Get-SNTPServer -server Machine1 | Set-SNTPServer -server Machine2
- This will get the sntp server for Machine1 and set Machine2 to the same
- .EXAMPLE
- PS C:\> Get-Content servers.txt | Set-SNTPServer -SNTPServerList "dc1,dc2"
- .NOTES
- NAME : Set-SNTPServer
- VERSION : 1.0
- LAST UPDATED: 04/04/2011
- AUTHOR : a Monkey
- .LINK
- http://amonkeysden.tumblr.com/post/4393059808/sntp-module
- #>
- function Set-SNTPServer
- {
- [cmdletbinding()]
- Param(
- [Parameter(
- Mandatory = $True,
- Position = 0,
- ParameterSetName = '',
- ValueFromPipeline = $True)]
- [string]$Server,
- [Parameter(
- Mandatory = $True,
- Position = 1,
- ParameterSetName = '',
- ValueFromPipeline = $True)]
- [string]$SNTPServerList
- )
- foreach ($s in $Server.Split(","))
- {
- [string] $z = net time \\$s /SETSNTP:$SNTPServerList
- if (($z.contains("The command completed successfully."))) {
- Write-Output $z
- } else {
- Write-Error $z
- }
- }
- }
- # export the functions to be used
- Export-ModuleMember Set-SNTPServer
- Export-ModuleMember Get-SNTPServer
SNTP by a Monkey 10 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2604"></script>download | new post
Get and Set functions for SNTP
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository