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
#requires -Modules PowerShellGet


$ReleaseNotes =@'

Invoke-WakeOnLan
 
Chris Warwick, @cjwarwickps, January 2012. This version, November 2015.
 
 
Cmdlet to send a Wake-on-Lan packet to a specified target MAC addresses.
 
 
Wake on Lan (WOL) uses a “Magic Packet” that consists of six bytes of 0xFF (the physical layer broadcast address), followed
by 16 copies of the 6-byte (48-bit) target MAC address (see http://en.wikipedia.org/wiki/Wake-on-LAN).
 
This packet is sent via UDP to the LAN Broadcast addresses (255.255.255.255) on arbitrary Port 4000.
 
Construction of this packet in PowerShell is very straight-forward: (“$Packet = [Byte[]](,0xFF*6)+($Mac*16)”).
 
This script has a (hard-coded) table of saved MAC addresses to allow machine aliases to be specified as parameters to the
function (the real addresses have been obfuscated here) and uses a regex to validate MAC address strings.
 
It would be possible to use DNS and the ARP Cache to resolve MAC addresses, however, the ARP cache will only be populated with
a valid entry for any given target adapter for a relative short period of time after the last use of the address (10 minutes
or less depending on usage); ARP cannot be used to dynamically resolve the address of a suspended adapter.
   
 
Script Help
-----------
 
<#
.Synopsis
    This cmdlet sends Wake-on-Lan Magic Packets to the specified Mac addresses.
.Description
    Wake on Lan (WOL) uses a “Magic Packet” that consists of six bytes of 0xFF (the physical layer broadcast address), followed
    by 16 copies of the 6-byte (48-bit) target MAC address (see http://en.wikipedia.org/wiki/Wake-on-LAN).
 
    This packet is sent via UDP to the LAN Broadcast addresses (255.255.255.255) on arbitrary Port 4000.
 
    Construction of this packet in PowerShell is very straight-forward: (“$Packet = [Byte[]](,0xFF*6)+($Mac*16)”).
 
    This script has a (hard-coded) table of saved MAC addresses to allow machine aliases to be specified as parameters to the
    function (the real addresses have been obfuscated here) and uses a regex to validate MAC address strings. The address
    aliases are contained in a hash table in the script - but they could very easily be obtained from an external source such as
    a text file or a CSV file (this is left as an exercise for the reader).
 
    It would be possible to use DNS and the ARP Cache to resolve MAC addresses, however, the ARP cache will only be populated with
    a valid entry for any given target adapter for a relative short period of time after the last use of the address (10 minutes
    or less depending on usage); ARP cannot be used to dynamically resolve the address of a suspended adapter.
.Example
    Invoke-WakeOnLan 00-1F-D0-98-CD-44
    Sends WOL packets to the specified address
.Example
    Invoke-WakeOnLan 00-1F-D0-98-CD-44, 00-1D-92-3B-C2-C8
    Sends WOL packets to the specified addresses
.Example
    00-1F-D0-98-CD-44, 00-1D-92-3B-C2-C8 | Invoke-WakeOnLan
    Sends WOL packets to the specified addresses
.Example
    Invoke-WakeOnLan Server3
    Sends WOL packets to the specified target using an alias. The alias must currently be hard-coded in the script.
.Inputs
    An array of MAC addresses. Each address must be specified as a sequence of 6 hex-coded bytes seperated by ':' or '-'
    The input can also contain aliases - these must currently be hard-coded in the script (see examples)
    MAC addresses can be piped to the cmdlet.
.Outputs
    Wake-on-Lan packets are sent to the specified addresses
.Parameter MacAddress
    An array of MAC addresses. Each address must be specified as a sequence of 6 hex-coded bytes seperated by ':' or '-'
.Functionality
    Sends Wake-on-Lan Magic Packets to the specified Mac addresses
#>
 
 
Version History:
---------------
 
 V1.0 (This Version)
  - Initial release to the PowerShell Gallery
 
 V0.1-0.9 Dev versions
 
Other Modules:
------------
See all my other PS Gallery modules:
 
  Find-Module | Where Author -match 'Chris Warwick'




'@


$Tags = @(
    'WakeOnLan'
    'WOL'
    'ARP'
    'MAC'
    'RFC826'
    'MagicPacket'
)

$PublishParams = @{
    Name            = 'WakeOnLan'
    NuGetApiKey     = 'XXXXRedactedXXXX'
    ReleaseNotes    = $ReleaseNotes
    Tags            = $Tags
    ProjectUri      = 'https://github.com/ChrisWarwick/WakeOnLan'
}



Publish-Module @PublishParams


# ...later

# Find-Module WakeOnLan