Compare commits

...

3 Commits

Author SHA1 Message Date
Asif Bacchus 7faa4d84c4 struct(modules): working skeleton magic-packet function
- function to send magic packet
- basic validation and error trapping
- need to use cleaner error trapping
- need to add inline help
2021-09-04 00:58:30 -06:00
Asif Bacchus abcbdb274d struct(data): sample XML list of computers 2021-09-04 00:56:59 -06:00
Asif Bacchus 10b0bfbdfa chore(IDE): Rider configuration files 2021-09-04 00:56:32 -06:00
6 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.ps-cmdlet-wol.iml
/modules.xml
/contentModel.xml
/projectSettingsUpdater.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectDictionaryState">
<dictionary name="asif" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CommitMessageInspectionProfile">
<profile version="1.0">
<inspection_tool class="BodyLimit" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SubjectBodySeparation" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SubjectLimit" enabled="true" level="ERROR" enabled_by_default="true" />
</profile>
</component>
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

15
computerList.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<db>
<Configuration>
<AlwaysAuthorized>
"ITStaff",
"Administrators",
"Domain Admins"
</AlwaysAuthorized>
</Configuration>
<Computers>
<Computer name="Computer001" mac="AA:1A:2A:3A:4A:01" authorized="any"/>
<Computer name="Computer002" mac="BB:1B:2B:3B:4B:02" authorized="Managers"/>
<Computer name="Computer003" mac="CC:1C:2C:3C:4C:03" authorized="User3"/>
</Computers>
</db>

79
wol-magicPacket.psm1 Normal file
View File

@ -0,0 +1,79 @@
function Send-MagicPacket
{
[CmdletBinding()]
param
(
# Array of MAC addresses for which to construct magic packets
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidatePattern('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$')]
[String[]]
$MacAddress,
# Broadcast IP address (default: all subnets --> 255.255.255.255)
[Parameter()]
[IPAddress]
$BroadcastIP = [System.Net.IPAddress]::Broadcast,
# UDP port over which to broadcast magic packet (default: 7)
[Parameter()]
[Int16]
$Port = 7
)
begin
{
# instantiate UDP client
try
{
$UdpClient = [System.Net.Sockets.UdpClient]::new()
}
catch
{
Write-Error "Unable to instantiate UDP Client to send magic packets"
}
}
process
{
foreach ($addr in $MacAddress)
{
# convert MAC address to magic packet
try
{
# construct byte-array from MAC address
$MAC = $addr -split '[:-]' | ForEach-Object {
[Byte]"0x$_"
}
# construct magic packet
# first 6 bytes = FF (255) then repeat MAC address 16 times
[Byte[]]$magicPacket = (,0xFF * 6) + ($MAC * 16)
}
catch
{
Write-Warning "Unable to process MAC address: $thisMacAddress"
continue
}
# broadcast magic packet
try
{
$UdpClient.Connect($BroadcastIP, $Port)
$UdpClient.Send($magicPacket, $magicPacket.Length) | Out-Null
Write-Verbose "Sent magic packet: Broadcast $addr over $BroadcastIP on port $Port (UDP)"
}
catch
{
Write-Warning "Unable to send magic packet for '$addr'"
continue
}
}
}
end
{
# dispose of UDP client
$UdpClient.Close()
$UdpClient.Dispose()
}
}