PublishPsGalleryModule.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#requires -Modules PowerShellGet


$ReleaseNotes =@'

Get-NtpTime
Chris Warwick, @cjwarwickps, September 2015.

v1.1 release to the PowerShell Gallery.

This module contains a single PS Function 'Get-NtpTime' which sends an NTP request to a specified NTP server and
decodes the returned raw NTP packet. The function will connect to pool.ntp.org if no server is specified.

I originally wrote this script to check NTP responses from Windows Domain Controllers - but it works with
any NTP server. See rfc-1305: http://www.faqs.org/rfcs/rfc1305.html

Refer to the PowerShell help and additional background information included in the module for further details.


.PARAMETER Server
    The NTP Server to contact. Uses pool.ntp.org by default.
 .PARAMETER MaxOffset
    The maximum acceptable offset between the local clock and the NTP Server, in milliseconds.
    The script will throw an exception if the time difference exceeds this value (on the assumption
    that the returned time may be incorrect). Default = 10000 (10s).
 .PARAMETER NoDns
    (Switch) If specified do not attempt to resolve Version 3 Secondary Server ReferenceIdentifiers.
 .EXAMPLE
    Get-NtpTime uk.pool.ntp.org
    Gets time from the specified server.
 .EXAMPLE
    Get-NtpTime | fl *
    Get time from default server (pool.ntp.org) and displays all output object attributes.
.EXAMPLE
    Get-NtpTime DC01.company.org
    Get time from a domain controller.

Usage:

 PS:\> Get-NtpTime


 NtpServer : pool.ntp.org
 NtpTime : 21/09/2015 12:17:26
 OffsetSeconds : -0.009
 NtpVersionNumber : 3
 Mode_text : server
 Stratum : 2
 ReferenceIdentifier : 195.66.241.2 <ntp0.linx.net>



 PS:\> Get-NtpTime -Server uk.pool.ntp.org | Format-List *


 NtpServer : uk.pool.ntp.org
 NtpTime : 21/09/2015 12:18:23
 Offset : -18.845458984375
 OffsetSeconds : -0.019
 Delay : 22.98193359375
 t1ms : 3588751103158.74
 t2ms : 3588751103151.39
 t3ms : 3588751103151.43
 t4ms : 3588751103181.77
 t1 : 21/09/2015 12:18:23
 t2 : 21/09/2015 12:18:23
 t3 : 21/09/2015 12:18:23
 t4 : 21/09/2015 12:18:23
 LI : 0
 LI_text : no warning
 NtpVersionNumber : 3
 Mode : 4
 Mode_text : server
 Stratum : 2
 Stratum_text : secondary reference (via NTP or SNTP)
 PollIntervalRaw : 0
 PollInterval : 00:00:01
 Precision : -23
 PrecisionSeconds : 1.19209289550781E-07
 ReferenceIdentifier : 195.66.241.2 <ntp0.linx.net>
 RootDelay : 0.003143310546875
 RootDispersion : 0.02679443359375
 Raw : {28, 2, 0, 233, 0, 0, 0, 206, 0, 0, 6, 220, 195, 66, 241, 2, 213, 231, 252, 27...}


 Version History:

 V1.1 (This version)
  - Updated help to reflect usage against domain controllers
  - Removed default display format code from script and replaced with .ps1xml format file

 V1.0 (Initial PowerShell Gallery version)
  - Copy with updates from original script
 
 V0.9 (Initial Technet ScriptCenter version)

 V0.1-0.8 Dev versions


'@


$Tags = @(
   'NTP'
   'PowerShell'
   'SNTP'
   'Network'
   'Time'
   'rfc1305'
   'rfc2030'
   'UDP'
   'ps1xml'
   'PsCustomObject'
)

$PublishParams = @{
    Name            = 'NtpTime'
    NuGetApiKey     = 'XXXXRedactedXXXX'
    ReleaseNotes    = $ReleaseNotes
    Tags            = $Tags
    ProjectUri      = 'https://github.com/ChrisWarwick/PowerShell-NTP-Time'
}



Publish-Module @PublishParams


# ...later

# Find-Module NtpTime