Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0aa0680ef | |||
b968fdf93e | |||
d5c3c071cd | |||
f389999ca3 | |||
1ff4a6bf6a |
54
README.md
54
README.md
@ -8,6 +8,7 @@ ## Contents
|
||||
<!-- toc -->
|
||||
|
||||
- [Installation and verification](#installation-and-verification)
|
||||
* [Example: Auto-load for current user](#example-auto-load-for-current-user)
|
||||
- [Overview](#overview)
|
||||
- [Broadcast considerations](#broadcast-considerations)
|
||||
- [Pipeline](#pipeline)
|
||||
@ -18,12 +19,53 @@ ## Contents
|
||||
|
||||
## Installation and verification
|
||||
|
||||
Downloads are available
|
||||
via [my git server (https://git.asifbacchus.dev/asif/ps-cmdlet-wol)](https://git.asifbacchus.dev/asif/ps-cmdlet-wol)
|
||||
and [GitHub (https://github.com/asifbacchus/ps-cmdlet-wol)](https://github.com/asifbacchus/ps-cmdlet-wol). You may
|
||||
verify the cmdlet's integrity using [CodeNotary](https://codenotary.io) via `vcn authenticate` or by dropping the
|
||||
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!
|
||||
Downloads are available via [my git server](https://git.asifbacchus.dev/asif/ps-cmdlet-wol/releases/latest)
|
||||
and [GitHub](https://github.com/asifbacchus/ps-cmdlet-wol/releases/latest). You may verify the cmdlet's integrity
|
||||
using [CodeNotary](https://codenotary.io) via `vcn authenticate` or by dropping the downloaded script and/or manifest
|
||||
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
|
||||
|
||||
|
BIN
wol-magicPacket.psd1
Normal file
BIN
wol-magicPacket.psd1
Normal file
Binary file not shown.
@ -50,7 +50,6 @@ function Send-MagicPacket
|
||||
ValueFromPipelineByPropertyName,
|
||||
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[]]
|
||||
$MacAddress,
|
||||
|
||||
@ -83,6 +82,13 @@ function Send-MagicPacket
|
||||
{
|
||||
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
|
||||
try
|
||||
{
|
||||
@ -97,7 +103,7 @@ function Send-MagicPacket
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Warning "Unable to process MAC address: $thisMacAddress"
|
||||
Write-Error "Unable to process MAC address: $thisMacAddress"
|
||||
continue
|
||||
}
|
||||
|
||||
@ -112,7 +118,7 @@ function Send-MagicPacket
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Warning "Unable to send magic packet for '$addr'"
|
||||
Write-Error "Unable to send magic packet for '$addr'"
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -124,4 +130,6 @@ function Send-MagicPacket
|
||||
$UdpClient.Close()
|
||||
$UdpClient.Dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Send-MagicPacket
|
||||
|
Loading…
Reference in New Issue
Block a user