Created
July 24, 2018 15:42
-
-
Save clintcolding/f83646dcb59ff5575945c20e8ee197e6 to your computer and use it in GitHub Desktop.
Bluecat/Proteus API PowerShell Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# API Documentation can be at http://timlossev.com/attachments/Proteus_API_Guide_3.7.1.pdf | |
# Connecting the the API | |
$credential = Get-Credential | |
$uri = "http://bluecatserver/Services/API?wsdl" | |
$bc = New-WebServiceProxy -Uri $uri | |
$bc.CookieContainer = New-Object System.Net.CookieContainer | |
$bc.login($Credential.UserName, ($Credential.GetNetworkCredential()).Password) | |
# Find IP based on assigned name in Bluecat | |
$name = "node1" | |
$bc.searchByObjectTypes("$name", "IP4Address", 0, 999) | |
# Assign/Update IP Assignments | |
$ip = '10.18.24.16' | |
$name = 'node2' | |
$record = $bc.getIP4Address(17,$ip) | |
if ($record.id -ne 0) { | |
if ($record.name -ne $name) { | |
if ($PSCmdlet.ShouldProcess("Replace $($record.name) with $($name) ?")) { | |
$record.name = $name | |
$bc.update($record) | |
} | |
} | |
} | |
if ($record.id -eq 0) { | |
$mac="" | |
$prop = "name=$name" | |
$bc.assignIP4Address(17,$ip,$mac,$name,"MAKE_STATIC",$prop) | |
} | |
# Remove IP Assignmnet | |
$name = 'node2' | |
$prop = $bc.searchByObjectTypes("$name", "IP4Address", 0, 1) | |
$bc.delete($prop.id) | |
# Get next IP within specified subnet | |
$subnet = "10.18.20.0" | |
$network = $bc.searchByObjectTypes("$subnet", "IP4Network", 0, 999) | |
$bc.getNextIP4Address("$($network.id)",([regex]::Matches($($network.properties),"(?<=defaultView=)\d{6}").value)) |
I believe the last version of Posh with New-WebServiceProxy was 5.1. You may be able to interact with a SOAP API using Invoke-WebRequest, this article gives a few examples.
I don't have access to a Bluecat instance anymore so I can no longer test.
Thank you Clintcolding!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has stopped working on Powershell core, though works perfectly on Desktop edition, it can't seem to understand New-WebServiceProxy cmdlet any more.
any examples of powershell with Bluecat's Rest API ? or a way to make this script work on powershell core