Hello and welcome to the forum.
Whenever you’re sharing code please make sure to use the Preformatted text button. It’s often behind the gear icon.
The first thing I did was look up the module you’re using. WakeOnLane was published to the PowerShell Gallery in 2015 and written with Powershell v2 as a minimum. Just things to keep in mind.
InvalidArgument: Cannot convert value "0x40:1c:83:40:ad:3f" to type "System.Byte"
Your MAC address suddenly has a 0x40
at the beginning of it instead of your original “40”.
The param block from the source code takes your input in as a string:
Param (
[Parameter(ValueFromPipeline)]
[String[]]$MacAddress
)
And later converts it to bytes:
$Mac = $MacString.Split('-:') | Foreach {[Byte]"0x$_"}
# WOL Packet is a byte array with the first six bytes 0xFF, followed by 16 copies of the MAC address
$Packet = [Byte[]](,0xFF * 6) + ($Mac * 16)
When I run just the relevant code in Windows Powershell v5.1 it works.
When I run it in Powershell 7.5 it fails with the error:
InvalidArgument: Cannot convert value "0x40:1c:83:40:ad:3f" to type "System.Byte". Error: "Additional non-parsable characters are at the end of the string."
I don’t know which part of this syntax it doesn’t like:
$Mac = $MacString.Split('-:') | Foreach {[Byte]"0x$_"}
But that’s your problem.
Seeing your PS prompt in your posted text we can see you’re on a Windows machine. I would advise using Windows Powershell to use this module instead.
I would also advise you edit your post and remove your username from your prompt as it reveals potentially sensitive information about your organization.
EDIT: got it. The author used the Split() method of a String object and included two characters to potentially split on: -, ;
In Windows Powershell v5.1, and .NET framework 4.5 that works:
# v5.1
PS> $MacString = "40:1c:83:40:ad:3f"
PS> $MacString.Split('-:')
40
1c
83
40
ad
3f
But in PS v7.5 it doesn’t split at all:
# v7.5
PS> $MacString = "40:1c:83:40:ad:3f"
PS> $MacString.Split('-:')
40:1c:83:40:ad:3f
The definition on [Microsoft’s docs]( String.Split Method (System) | Microsoft Learn) for both version of .NET says that Split will accept an array of characters as delimiters. But simply passing '-:'
isn’t strictly an array, but somehow this worked in older versions of Powershell.
I was able to make it work in both versions by literally creating a character array.
$MacString = "40:1c:83:40:ad:3f"
[Char[]]$Chars = [Char]'-',[Char]':'
$MacString.Split($Chars)# | Foreach {[Byte]"0x$_"}
@LearnLaughOps solution of switching to the -Split operator with Regex pattern of This|That is what I would do.
You can edit your local copy of the module manually yourself, open an issue on github, or fork the project for yourself.