Skip to content

Instantly share code, notes, and snippets.

@dkittell
Created December 22, 2015 12:27
Show Gist options
  • Save dkittell/65890843f6224e45bb4e to your computer and use it in GitHub Desktop.
Save dkittell/65890843f6224e45bb4e to your computer and use it in GitHub Desktop.
PowerShell - REST Client
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment