KVBtools.psm1
function convert-kmacaddress { param ( [Parameter(Mandatory,ValueFromPipeline)] $macaddress ) Process{ $ErrorActionPreference = "silent" foreach($mac in $macaddress) { #Clearing at start of the loop $CleanMac="" for($i=0;$i -lt $mac.length;$i++) { #Regex filter to see if Mac is possibly a legal mac. Not 100% deterministic. This tries to bring all input to 12-chars format. $check = $mac.substring($i,1) -match '[a-f]|[0-9]' if ($check) { $CleanMac += $mac.substring($i,1) } } if ($CleanMac.length -eq 12) { $CiscoMac = $CleanMac.insert(4,".").insert(9,".") $MSMac = $CleanMac.insert(2,"-").insert(5,"-").insert(8,"-").insert(11,"-").insert(14,"-") $LMac = $CleanMac.insert(2,":").insert(5,":").insert(8,":").insert(11,":").insert(14,":") $all = "$Ciscomac $Msmac $Lmac" $all | ConvertFrom-String -PropertyNames Ciscomac, MSMac, LinuxMac } else { $CiscoMac = "Invalid" $MSMac = "Invalid" $LMac = "Invalid" $all = "$Ciscomac $Msmac $Lmac" $all | ConvertFrom-String -PropertyNames Ciscomac, MSMac, LinuxMac } } } } "3A-15-A6-C1-88-1AA","3A-15-A6-C1-88-AA" | convert-kmacaddress |