First listed source code is without authentication, whereas the second is with basic authentication
param ( [Parameter( Mandatory=$true)] [string]$Address ) clear function Get-MAC() { param($Address) begin { $APIURL = "http://<URL>/address.xml?&search=" $resource = "$($APIURL)$($Address)" $mac = Invoke-RestMethod -URI $resource -Method Get $hash = @{ Status_Code = $mac.Response.Status_Code Company_Name = $mac.Response.Company_Name MAC_Address = $mac.Response.MAC_Address } $result = New-Object PSObject -Property $hash | Format-Table Company_Name -AutoSize return $result } } Get-MAC($Address)
param ( [Parameter( Mandatory=$true)] [string]$Address ) clear function Get-MAC() { param($Address) begin { $APIURL = "http://<URL>/address.xml?&search=" $resource = "$($APIURL)$($Address)" $username="Username" $password="Password" $mac = Invoke-RestMethod -URI $resource -Headers @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))} -Method Get $hash = @{ Status_Code = $mac.Response.Status_Code Company_Name = $mac.Response.Company_Name MAC_Address = $mac.Response.MAC_Address } $result = New-Object PSObject -Property $hash | Format-Table Company_Name -AutoSize return $result } } Get-MAC($Address)
GitHub: https://gist.github.com/dkittell/65890843f6224e45bb4e
Last Updated on February 12, 2016