Public/Get-MacVendor.ps1
|
function Get-MacVendor { <# .SYNOPSIS Resolve a MAC address to its registered vendor name. No API key required. .DESCRIPTION Calls GET /v1/vendor/:mac, the keyless name-only endpoint. Returns the vendor name as a string, or $null when the address is valid but has no vendor to report: an unregistered prefix, the broadcast address, or a locally administered / privacy-randomized address. Use Resolve-MacAddress when you need to tell those cases apart. Accepts one or more addresses from the pipeline. .PARAMETER MacAddress One or more MAC addresses, in any common notation (00:03:93:AB:12:34, 00-03-93-ab-12-34, 000393AB1234, 0003.93ab.1234). .PARAMETER PassThru Emit an object with MacAddress, Vendor and Oui instead of the bare vendor string. .PARAMETER ApiKey Optional API key. A keyed call still works here and counts against a larger daily grant before it touches your plan quota. .EXAMPLE Get-MacVendor 00:03:93:AB:12:34 Apple, Inc. .EXAMPLE '00:03:93:00:00:00', '3C:22:FB:00:00:00' | Get-MacVendor -PassThru .EXAMPLE Get-NetAdapter | ForEach-Object MacAddress | Get-MacVendor .LINK https://macadress.com/docs .LINK https://github.com/sapisos/macadress-powershell #> [CmdletBinding()] [OutputType([string])] [OutputType('Macadress.VendorName')] param( [Parameter(Mandatory, Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] [Alias('Mac', 'Address', 'PhysicalAddress')] [string[]] $MacAddress, [Parameter()] [switch] $PassThru, [Parameter()] [string] $ApiKey ) process { foreach ($mac in $MacAddress) { $trimmed = $mac.Trim() if (-not $trimmed) { continue } try { $name = Invoke-MacadressApi -Method GET -Path "v1/vendor/$(ConvertTo-MacadressPathSegment $trimmed)" -ApiKey $ApiKey -Raw $name = if ($null -eq $name) { $null } else { $name.Trim() } } catch { if ($_.Exception.Data['StatusCode'] -eq 404) { $name = $null } else { Write-Error -ErrorRecord $_ continue } } if ($PassThru) { [pscustomobject]@{ PSTypeName = 'Macadress.VendorName' MacAddress = $trimmed Vendor = $name Oui = ConvertTo-MacadressOui -MacAddress $trimmed } } else { $name } } } } |