Initial commit

This commit is contained in:
2022-11-30 16:53:56 +03:00
parent 11d98e7007
commit 50c048eb34
25 changed files with 1534 additions and 1 deletions

View File

@@ -0,0 +1,64 @@
function Invoke-PSIPAMRequest {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateSet("POST","GET","PATCH","DELETE")]
[string]
$Method,
[parameter(Mandatory=$true)]
[ValidateSet("user","vlan","subnets","addresses","sections","vrf","l2domains","tools")]
[string]
$Controller,
[parameter(Mandatory=$false)]
[ValidateSet("nameservers")]
[string]
$SubController,
[Parameter(Mandatory=$false)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$Params,
[Parameter(Mandatory=$false)]
[array]
$Identifiers
)
$_tokenStatus = Test-PSIPAMSession
if ($_tokenStatus -eq "NoToken") { throw "No session available!" }
if ($_tokenStatus -eq "Expired") { Update-PSIPAMSession }
$Controller = $Controller.ToLower()
$_uri = "$($script:ipamURL)/api/$($script:ipamAppID)/$Controller"
if ($SubController) { $_uri += "/$SubController" }
if ($Identifiers) { $_uri += "/$($Identifiers -join '/')/" }
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
"token" = $script:ipamToken
}
$_arguments = @{
Method = $Method
Uri = $_uri
Headers = $_headers
}
if ($Method -match "POST|PATCH") {
if ($Params -is [PSCustomObject]) {
$_params = @{};
$Params | Get-Member -MemberType *Property | Where-Object {
$_params.($_.name) = $Params.($_.name)
}
} else { $_params = $Params }
$_arguments.Add("Body",($_params | ConvertTo-Json))
}
$_response = Invoke-RestMethod @_arguments
if ($_response.code -match "20\d") {
return $_response.data
} else {
throw ("Error - $($_response.code)")
}
}

View File

@@ -0,0 +1,15 @@
function Test-PSIPAMSession {
[CmdletBinding()]
param (
)
if ($script:ipamToken) {
if ($script:ipamExpires -lt (Get-Date)) {
return "Expired"
} else {
return "Valid"
}
} else {
return "NoToken"
}
}

View File

@@ -0,0 +1,18 @@
function Update-PSIPAMSession {
[CmdletBinding()]
param (
[switch]
$Force
)
$_tokenStatus = Test-PSIPAMSession
if ($_tokenStatus -eq "NoToken") {
throw "No session available!"
}
if ($_tokenStatus -eq "Valid") {
return (Invoke-PSIPAMRequest -Method PATCH -Controller user).expires
}
if ($_tokenStatus -eq "Expired" -or $Force) {
New-PSIPAMSession -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials
return $script:ipamExpires
}
}

View File

@@ -0,0 +1,70 @@
function Get-PSIPAMAddress {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByIP")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="BySubnetId")]
[ValidateScript({[ipaddress] $_})]
[ValidateNotNullOrEmpty()]
[string]
$IP,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByHostName")]
[ValidateNotNullOrEmpty()]
[string]
$HostName,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByTag")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$TagId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SubnetId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetCIDR")]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$SubnetCIDR
)
process {
[string[]]$visiblePropertiesList = @('Id','Ip','Hostname','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "addresses"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($id) }
"ByIP" { $_identifiers = ("search",$IP) }
"ByHostName" { $_identifiers = ("search_hostname",$HostName) }
"ByTag" { $_identifiers = ("tags",$TagId,"addresses") }
"BySubnetId" {
if ($IP) {
$_identifiers = ($IP,$SubnetId)
} else {
$_params.Item("Controller") = "subnets"
$_identifiers = ($SubnetId,"addresses")
}
}
"BySubnetCIDR" {
$_params.Item("Controller") = "subnets"
$_subnetId = (Get-PSIPAMSubnet -CIDR $SubnetCIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" }
$_identifiers = ($_subnetId,"addresses")
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMAddress

View File

@@ -0,0 +1,33 @@
function Get-PSIPAMFirstFreeIP {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$CIDR,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
$_params = @{
Controller = "subnets"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_subnetId = $Id }
"ByCIDR" {
$_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" }
}
}
$_identifiers = @($_subnetId,"first_free")
$_params.Add("Identifiers",$_identifiers)
return Invoke-PSIPAMRequest @_params | Select-Object @{n="Ip";e={$_}}
}
}
Export-ModuleMember -Function Get-PSIPAMFirstFreeIP

View File

@@ -0,0 +1,26 @@
function Get-PSIPAML2Domain {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "l2domains"
Method = "GET"
}
$_identifiers = @($Id)
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAML2Domain

View File

@@ -0,0 +1,29 @@
function Get-PSIPAMNameserver {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Address','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "tools"
SubController = "nameservers"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_nameserverId = $Id }
}
$_identifiers = @($_nameserverId)
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="address";e={$_.namesrv1}},* | Select-Object -ExcludeProperty namesrv1 | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMNameserver

View File

@@ -0,0 +1,32 @@
function Get-PSIPAMSection {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByName")]
[ValidateNotNullOrEmpty()]
[string]
$Name
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "sections"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id) }
"ByName" { $_identifiers = @($Name) }
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember Get-PSIPAMSection

View File

@@ -0,0 +1,129 @@
function Get-PSIPAMSubnet {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$CIDR,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionId")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="ByVlanNumber")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SectionId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionName")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3,ParameterSetName="ByVlanNumber")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="ByVlanId")]
[ValidateNotNullOrEmpty()]
[string]
$SectionName,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVrfId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$VrfId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$VlanId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanNumber")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$VlanNumber,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanNumber")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$VlanDomain,
[parameter(Mandatory=$false,ParameterSetName="ByID")]
[switch]
$Slaves,
[parameter(Mandatory=$false,ParameterSetName="ByID")]
[switch]
$Recurse
)
process {
[string[]]$visiblePropertiesList = @('Id','Subnet','Mask','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "subnets"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByCIDR" {
$_identifiers = @("cidr",$CIDR)
}
"ByID" {
$_identifiers = @($Id)
if ($Slaves) {
if ($Recurse) {
$_identifiers += "slaves_recursive"
} else {
$_identifiers += "slaves"
}
}
}
"BySectionId" {
$_params.Item("Controller") = "sections"
$_sectionId = $SectionId
$_identifiers = @($_sectionId,"subnets")
}
"BySectionName" {
$_params.Item("Controller") = "sections"
$_sectionId = (Get-PSIPAMSection -Name $SectionName).id
if (!$_sectionId) { throw "Cannot find section!" }
$_identifiers = @($_sectionId,"subnets")
}
"ByVrfId" {
$_params.Item("Controller") = "vrf"
$_vrfId = $VrfId
$_identifiers = @($_vrfId,"subnets")
}
"ByVlanId" {
$_params.Item("Controller") = "vlan"
$_vlanId = $VlanId
if ($SectionId) { $_sectionId = $SectionId }
if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id }
$_identifiers = @($_vlanId,"subnets")
if ($_sectionId) { $_identifiers += $_sectionId }
}
"ByVlanNumber" {
$_params.Item("Controller") = "vlan"
$_vlans = Get-PSIPAMVlan -Number $VlanNumber
if ($VlanDomain) { $_vlans = $_vlans | Where-Object {$_.domainId -eq $VlanDomain} }
if ($SectionId) { $_sectionId = $SectionId }
if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id }
$_vlanId = $_vlans.vlanId
if ($_vlanid -is [System.Array]) { throw "More than one vLan with $VlanNumber number is present!" }
if (!$_vlanId) { throw "Cannot find Vlan!"}
$_identifiers = @($_vlanId,"subnets")
if ($_sectionId) { $_identifiers += $_sectionId }
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember Get-PSIPAMSubnet

View File

@@ -0,0 +1,33 @@
function Get-PSIPAMSubnetUsage {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$CIDR,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
$_params = @{
Controller = "subnets"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByCIDR" {
$_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" }
}
"ByID" { $_subnetId = $Id }
}
$_identifiers = @($_subnetId,"usage")
$_params.Add("Identifiers",$_identifiers)
return Invoke-PSIPAMRequest @_params
}
}
Export-ModuleMember -Function Get-PSIPAMSubnetUsage

View File

@@ -0,0 +1,26 @@
function Get-PSIPAMTags {
[CmdletBinding()]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "addresses"
Method = "GET"
}
$_identifiers = @("tags")
if ($Id) { $_identifiers += $Id }
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMTags

View File

@@ -0,0 +1,45 @@
function Get-PSIPAMVlan {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByNumber")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Number,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByL2Domain")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$L2DomainId
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "vlan"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id) }
"ByNumber" { $_identifiers = @("search",$Number) }
"ByL2Domain"{
$_params.Item("Controller") = "l2domains"
$_l2domainId = $L2DomainId
$_identifiers = @($_l2domainId,"vlans")
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vlanId}},* | Select-Object -ExcludeProperty vlanId | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMVlan

View File

@@ -0,0 +1,26 @@
function Get-PSIPAMVrf {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "vrf"
Method = "GET"
}
if ($Id) { $_identifiers = @($Id) }
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMVrf

View File

@@ -0,0 +1,182 @@
function New-PSIPAMAddress {
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SubnetId,
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="IP address",
Position=1)]
[ValidateScript({[ipaddress] $_ })]
[ValidateNotNullOrEmpty()]
[string]
$Ip,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Defines if address is presented as gateway",
Position=2)]
[switch]
$Gateway,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address description",
Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Description,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address hostname",
Position=4)]
[ValidateNotNullOrEmpty()]
[string]
$Hostname,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Mac address",
Position=5)]
[ValidateScript({ $_.Replace(":","") -match "^$('([A-F0-9]{2})' * 6)$" })]
[ValidateNotNullOrEmpty()]
[string]
$MAC,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address owner",
Position=6)]
[ValidateNotNullOrEmpty()]
[string]
$Owner,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=7)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$TagId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if PTR should not be created",
Position=8)]
[switch]
$PTRIgnore,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of PowerDNS PTR record",
Position=7)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$PTRId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Note",
Position=10)]
[ValidateNotNullOrEmpty()]
[string]
$Note,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Exclude this address from status update scans (ping)",
Position=11)]
[switch]
$ExcludePing,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of device address belongs to",
Position=12)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$DeviceId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Port",
Position=13)]
[ValidateNotNullOrEmpty()]
[string]
$Port,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$CustomFields
)
process {
$_params = @{
Controller = "addresses"
Method = "POST"
}
$_body = @{
subnetId = $SubnetId
ip = $Ip
}
if ($Gateway) { $_body.Add("is_gateway", "1") }
if ($Description) { $_body.Add("description", $Description) }
if ($Hostname) { $_body.Add("hostname", $Hostname) }
if ($MAC) { $_body.Add("mac", $MAC) }
if ($Owner) { $_body.Add("owner", $Owner) }
if ($TagId) { $_body.Add("tag", $TagId) }
if ($PTRIgnore) { $_body.Add("PTRignore", "1") }
if ($PTRId) { $_body.add("PTR", $PTRId)}
if ($Note) { $_body.Add("note", $Note) }
if ($ExcludePing) { $_body.Add("excludePing", "1") }
if ($DeviceId) { $_body.Add("deviceId", $DeviceId) }
if ($Port) { $_body.Add("port", $Port) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
try {
Invoke-PSIPAMRequest @_params
}
finally {
Get-PSIPAMAddress -SubnetId $SubnetId -Ip $Ip
}
}
}
Export-ModuleMember -Function New-PSIPAMAddress

View File

@@ -0,0 +1,172 @@
function New-PSIPAMFirstFreeIP {
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SubnetId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Defines if address is presented as gateway",
Position=2)]
[switch]
$Gateway,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address description",
Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Description,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address hostname",
Position=4)]
[ValidateNotNullOrEmpty()]
[string]
$Hostname,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Mac address",
Position=5)]
[ValidateScript({ $_.Replace(":","") -match "^$('([A-F0-9]{2})' * 6)$" })]
[ValidateNotNullOrEmpty()]
[string]
$MAC,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address owner",
Position=6)]
[ValidateNotNullOrEmpty()]
[string]
$Owner,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=7)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$TagId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if PTR should not be created",
Position=8)]
[switch]
$PTRIgnore,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of PowerDNS PTR record",
Position=9)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$PTRId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Note",
Position=10)]
[ValidateNotNullOrEmpty()]
[string]
$Note,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Exclude this address from status update scans (ping)",
Position=11)]
[switch]
$ExcludePing,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of device address belongs to",
Position=12)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$DeviceId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Port",
Position=13)]
[ValidateNotNullOrEmpty()]
[string]
$Port,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$CustomFields
)
process {
$_params = @{
Controller = "addresses"
Method = "POST"
}
$_identifiers = @('first_free')
$_params.Add("Identifiers",$_identifiers)
$_body = @{
subnetId = $SubnetId
}
if ($Gateway) { $_body.Add("is_gateway", "1") }
if ($Description) { $_body.Add("description", $Description) }
if ($Hostname) { $_body.Add("hostname", $Hostname) }
if ($MAC) { $_body.Add("mac", $MAC) }
if ($Owner) { $_body.Add("owner", $Owner) }
if ($TagId) { $_body.Add("tag", $TagId) }
if ($PTRIgnore) { $_body.Add("PTRignore", "1") }
if ($PTRId) { $_body.add("PTR", $PTRId)}
if ($Note) { $_body.Add("note", $Note) }
if ($ExcludePing) { $_body.Add("excludePing", "1") }
if ($DeviceId) { $_body.Add("deviceId", $DeviceId) }
if ($Port) { $_body.Add("port", $Port) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
$_result = Invoke-PSIPAMRequest @_params
if ($_result) {
Get-PSIPAMAddress -SubnetId $SubnetId -IP $_result
}
}
}
Export-ModuleMember -Function New-PSIPAMFirstFreeIP

View File

@@ -0,0 +1,37 @@
function New-PSIPAMSession {
[CmdletBinding()]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[string]$URL,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string]$AppID,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2)]
[ValidateNotNullOrEmpty()]
[pscredential]$Credentials
)
$_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password)
$_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr)
$_uri = "$URL/api/$AppID/user"
$_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password"))
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
"Authorization" = "Basic $_auth"
}
$_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue
if ($_response.success -eq $true) {
$script:ipamAuth = $true
$script:ipamToken = $_response.data.token
$script:ipamAppID = $AppID
$script:ipamURL = $URL
$script:ipamCredentials = $Credentials
$script:ipamExpires = Get-Date $_response.data.expires
} else {
$_response.error
}
}
Export-ModuleMember -Function New-PSIPAMSession

View File

@@ -0,0 +1,202 @@
function New-PSIPAMSubnet {
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="CIDR of subnet in dotted format (e.g 10.10.10.0/24)",
Position=0)]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$CIDR,
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Section identifier",
Position=1)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SectionId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Subnet description",
Position=2)]
[string]
$Description,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Assigns subnet to VLAN",
Position=3)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$VlanId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Assigns subnet to VRF",
Position=4)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$VrfId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Master subnet id for nested subnet",
Position=5)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$MasterSubnetId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of nameserver to attach to subnet",
Position=6)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$NameserverId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu",
Position=7)]
[switch]
$ShowName,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if PTR records should be created for subnet",
Position=8)]
[switch]
$DNSRecursive,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls weather hostname DNS records are displayed",
Position=9)]
[switch]
$DNSRecords,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if IP requests are allowed for subnet",
Position=10)]
[switch]
$AllowRequests,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls which scanagent to use for subnet (default id 1)",
Position=11)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$ScanAgentId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if new hosts should be discovered for new host scans",
Position=12)]
[switch]
$DiscoverSubnet,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Marks subnet as used",
Position=12)]
[switch]
$IsFull,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Assignes state (tag) to subnet (default: 1 Used)",
Position=12)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$TagId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Subnet threshold",
Position=13)]
[ValidateScript({ $_ -match "^\d+$" -and $_ -le 100 -and $_ -ge 1 })]
$Threshold,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Location index",
Position=14)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$LocationId,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$CustomFields
)
process {
$_params = @{
Controller = "subnets"
Method = "POST"
}
$_body = @{
subnet = $CIDR.Split('/')[0]
mask = $CIDR.Split('/')[1]
sectionId = $SectionId
}
if ($Description) { $_body.Add("description", $Description) }
if ($VlanId) { $_body.Add("vlanId", $VlanId) }
if ($VrfId) { $_body.Add("vrfId", $VrfId) }
if ($MasterSubnetId) { $_body.Add("masterSubnetId", $MasterSubnetId) }
if ($NameserverId) { $_body.Add("nameserverId", $NameserverId) }
if ($ShowName) { $_body.Add("showName", "1") }
if ($DNSRecursive) { $_body.Add("DNSrecursive", "1") }
if ($DNSRecords) { $_body.Add("DNSrecords", "1") }
if ($AllowRequests) { $_body.Add("allowRequests", "1") }
if ($ScanAgentId) { $_body.Add("scanAgent", $ScanAgentId) }
if ($DiscoverSubnet) { $_body.Add("discoverSubnet", "1") }
if ($IsFull) { $_body.Add("isFull", "1") }
if ($TagId) { $_body.Add("state", $TagId) }
if ($Threshold) { $_body.Add("threshold", $Threshold) }
if ($Location) { $_body.Add("location", $Location) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
$_result = Invoke-PSIPAMRequest @_params
if ($_result) {
return Get-PSIPAMSubnet -CIDR $_result
}
}
}
Export-ModuleMember -Function New-PSIPAMSubnet

View File

@@ -0,0 +1,35 @@
function Remove-PSIPAMAddress {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByIP")]
[ValidateScript({[ipaddress] $_ })]
[ValidateNotNullOrEmpty()]
[string]
$IP,
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=1,ParameterSetName="ByIP")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SubnetId
)
process {
$_params = @{
Controller = "addresses"
Method = "DELETE"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id) }
"ByIP" { $_identifiers = @($IP,$SubnetId) }
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params
}
}
Export-ModuleMember Remove-PSIPAMAddress

View File

@@ -0,0 +1,172 @@
function Set-PSIPAMAddress {
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Defines if address is presented as gateway",
Position=1)]
[bool]
$Gateway,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address description",
Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Description,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address hostname",
Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Hostname,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Mac address",
Position=4)]
[ValidateScript({ $_.Replace(":","") -match "^$('([A-F0-9]{2})' * 6)$" })]
[ValidateNotNullOrEmpty()]
[string]
$MAC,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address owner",
Position=5)]
[ValidateNotNullOrEmpty()]
[string]
$Owner,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=6)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$TagId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if PTR should not be created",
Position=7)]
[bool]
$PTRIgnore,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of PowerDNS PTR record",
Position=8)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$PTRId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Note",
Position=9)]
[ValidateNotNullOrEmpty()]
[string]
$Note,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Exclude this address from status update scans (ping)",
Position=10)]
[bool]
$ExcludePing,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of device address belongs to",
Position=11)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$DeviceId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Port",
Position=12)]
[ValidateNotNullOrEmpty()]
[string]
$Port,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$CustomFields
)
process {
$_params = @{
Controller = "addresses"
Method = "PATCH"
}
$_identifiers = @($Id)
$_params.Add("Identifiers",$_identifiers)
$_body = @{ }
if ($Gateway) { $_body.Add("is_gateway", [int]$Gateway) }
if ($Description) { $_body.Add("description", $Description) }
if ($Hostname) { $_body.Add("hostname", $Hostname) }
if ($MAC) { $_body.Add("mac", $MAC) }
if ($Owner) { $_body.Add("owner", $Owner) }
if ($TagId) { $_body.Add("tag", $TagId) }
if ($PTRIgnore) { $_body.Add("PTRignore", [int]$PTRIgnore) }
if ($PTRId) { $_body.add("PTR", $PTRId)}
if ($Note) { $_body.Add("note", $Note) }
if ($ExcludePing) { $_body.Add("excludePing", [int]$ExcludePing) }
if ($DeviceId) { $_body.Add("deviceId", $DeviceId) }
if ($Port) { $_body.Add("port", $Port) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
try {
Invoke-PSIPAMRequest @_params
}
finally {
Get-PSIPAMAddress -Id $Id
}
}
}
Export-ModuleMember -Function Set-PSIPAMAddress

View File