I am trying to build a wake on LAN script that invoke's a command on a machine to send packets to others.
I read in machine names and MAC addresses from a SQL server database, and use those variables ($item) to sent he packets.
When the script gets to the wake on LAN portion, I get this error
Exception calling ".ctor" with "2" argument(s): "Value cannot be null.
The wake on LAN portion is here:
if($offMachines.Count -gt 0){
Write-Host "Using $($on) to broadcast WOL to requested machines."
Invoke-Command -ComputerName $on -ScriptBlock{
foreach($item in $args){
[net.ipaddress]$broadcast = $item.Broadcast
$mac = [Net.NetworkInformation.PhysicalAddress]::Parse($item.MAC.ToUpper().replace(":","").replace("-","").replace(".",""))
$udp = New-Object net.sockets.udpclient
$ep = New-Object net.ipendpoint $broadcast, 7
$payload = [byte[]]@(255,255,255, 255,255,255);
$payload += ($mac.GetAddressBytes()*16)
$udp.Send($payload, $payload.Length, $ep) | Out-Null
write-host "WOL command sent to $($item.NAME)"
Start-Sleep -Seconds 2
}
} -ArgumentList $offMachines
}
I believe my error comes from the $udp and $ep variables above.
Any advice is greatly appreciated.
The full error is
Exception calling ".ctor" with "2" argument(s): "Value cannot be null.
Parameter name: address"
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
+ PSComputerName : TESTMACHINE
- Edited by jkg_admin Wednesday, August 19, 2015 2:37 PM


