Compare commits

..

No commits in common. "main" and "v1.0" have entirely different histories.
main ... v1.0

3 changed files with 10 additions and 60 deletions

View File

@ -8,7 +8,6 @@ ## Contents
<!-- toc --> <!-- toc -->
- [Installation and verification](#installation-and-verification) - [Installation and verification](#installation-and-verification)
* [Example: Auto-load for current user](#example-auto-load-for-current-user)
- [Overview](#overview) - [Overview](#overview)
- [Broadcast considerations](#broadcast-considerations) - [Broadcast considerations](#broadcast-considerations)
- [Pipeline](#pipeline) - [Pipeline](#pipeline)
@ -19,53 +18,12 @@ ## Contents
## Installation and verification ## Installation and verification
Downloads are available via [my git server](https://git.asifbacchus.dev/asif/ps-cmdlet-wol/releases/latest) Downloads are available
and [GitHub](https://github.com/asifbacchus/ps-cmdlet-wol/releases/latest). You may verify the cmdlet's integrity via [my git server (https://git.asifbacchus.dev/asif/ps-cmdlet-wol)](https://git.asifbacchus.dev/asif/ps-cmdlet-wol)
using [CodeNotary](https://codenotary.io) via `vcn authenticate` or by dropping the downloaded script and/or manifest and [GitHub (https://github.com/asifbacchus/ps-cmdlet-wol)](https://github.com/asifbacchus/ps-cmdlet-wol). You may
onto their verification webpage at [https://verify.codenotary.io](https://verify.codenotary.io). Please always try to verify the cmdlet's integrity using [CodeNotary](https://codenotary.io) via `vcn authenticate` or by dropping the
verify downloaded scripts and software regardless of the source! downloaded script onto their verification webpage at [https://verify.codenotary.io](https://verify.codenotary.io).
Please always try to verify downloaded scripts and software regardless of the source!
If you are integrating this function with your own project or want to manually load the module as needed, then save the
module and manifest file wherever it is convenient for you. If you want to auto-load this function so it is available
automatically in any PowerShell session then you *must* extract it to a directory named **wol-magicPacket** somewhere
defined in your `PSModulePath` depending on your use-case. More information can be found directly from
Microsoft [here](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_modules?view=powershell-7.1#short-description)
.
### Example: Auto-load for current user
Here's a complete example assuming I want the module automatically available for all sessions running under my user
account:
```powershell
# download version 2.0
Invoke-WebRequest -Uri https://git.asifbacchus.dev/asif/ps-cmdlet-wol/archive/v2.0.zip -OutFile "$Env:DOWNLOADS\ps-cmdlet-wol.zip"
# Get PSModulePath
# You should see a user-level modules path in the form of either:
# C:\Users\Username\Documents\WindowsPowerShell\Modules -OR-
# C:\Users\Username\Documents\PowerShell\Modules
$Env:PSModulePath
# change directory to the appropriate path from above
Set-Location "C:\Users\Username\Documents\WindowsPowerShell\Modules"
# extract files and rename directory
Expand-Archive -Path "$Env:DOWNLOADS\ps-cmdlet-wol.zip" -DestinationPath .\
Rename-Item -Path ps-cmdlet-wol -NewName wol-magicPacket
# confirm: you should see a directory named 'wol-magicPacket'
gci
# confirm: you should see the manifest and module within the wol-magicPacket folder
gci .\wol-magicPacket
```
Now, close and re-open PowerShell and the `Send-MagicPacket` function should be available:
```powershell
Get-Command Send-MagicPacket
```
## Overview ## Overview

Binary file not shown.

View File

@ -50,6 +50,7 @@ function Send-MagicPacket
ValueFromPipelineByPropertyName, ValueFromPipelineByPropertyName,
HelpMessage = "Please provide one or more MAC addresses. You may use a colon (:) or a hypen (-) to separate hex values." HelpMessage = "Please provide one or more MAC addresses. You may use a colon (:) or a hypen (-) to separate hex values."
)] )]
[ValidatePattern('^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$')]
[String[]] [String[]]
$MacAddress, $MacAddress,
@ -82,13 +83,6 @@ function Send-MagicPacket
{ {
foreach ($addr in $MacAddress) foreach ($addr in $MacAddress)
{ {
# validate MAC address format or write error and continue
if (!($addr -match '^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$'))
{
Write-Error "Invalid MAC address: $addr"
continue
}
# convert MAC address to magic packet # convert MAC address to magic packet
try try
{ {
@ -103,7 +97,7 @@ function Send-MagicPacket
} }
catch catch
{ {
Write-Error "Unable to process MAC address: $thisMacAddress" Write-Warning "Unable to process MAC address: $thisMacAddress"
continue continue
} }
@ -118,7 +112,7 @@ function Send-MagicPacket
} }
catch catch
{ {
Write-Error "Unable to send magic packet for '$addr'" Write-Warning "Unable to send magic packet for '$addr'"
continue continue
} }
} }
@ -130,6 +124,4 @@ function Send-MagicPacket
$UdpClient.Close() $UdpClient.Close()
$UdpClient.Dispose() $UdpClient.Dispose()
} }
} }
Export-ModuleMember -Function Send-MagicPacket