Documented new-subnet
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
function New-Address {
|
function New-Address {
|
||||||
|
[OutputType([PS.IPAM.address])]
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
[parameter(
|
[parameter(
|
||||||
|
|||||||
@@ -107,6 +107,5 @@ function New-Session {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $script:psipamSession
|
|
||||||
}
|
}
|
||||||
Export-ModuleMember -Function New-Session
|
Export-ModuleMember -Function New-Session
|
||||||
@@ -1,78 +1,225 @@
|
|||||||
function New-Subnet {
|
function New-Subnet {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
|
||||||
|
Creates new subnetwork object.
|
||||||
|
|
||||||
|
.PARAMETER CIDR
|
||||||
|
CIDR of subnet in dotted format (e.g 10.10.10.0/24).
|
||||||
|
|
||||||
|
.PARAMETER SectionId
|
||||||
|
Section identifier.
|
||||||
|
|
||||||
|
.PARAMETER Description
|
||||||
|
Subnet description.
|
||||||
|
|
||||||
|
.PARAMETER VlanId
|
||||||
|
Assigns subnet to VLAN.
|
||||||
|
|
||||||
|
.PARAMETER VrfId
|
||||||
|
Assigns subnet to VRF.
|
||||||
|
|
||||||
|
.PARAMETER MasterSubnetId
|
||||||
|
Master subnet id for nested subnet.
|
||||||
|
|
||||||
|
.PARAMETER NameserverId
|
||||||
|
Id of nameserver to attach to subnet.
|
||||||
|
|
||||||
|
.PARAMETER ShowName
|
||||||
|
Controls weather subnet is displayed as IP address or Name in subnets menu.
|
||||||
|
|
||||||
|
.PARAMETER DNSRecursive
|
||||||
|
Controls if PTR records should be created for subnet.
|
||||||
|
|
||||||
|
.PARAMETER DNSRecords
|
||||||
|
Controls weather hostname DNS records are displayed.
|
||||||
|
|
||||||
|
.PARAMETER AllowRequests
|
||||||
|
Controls if IP requests are allowed for subnet.
|
||||||
|
|
||||||
|
.PARAMETER ScanAgentId
|
||||||
|
Controls which scanagent to use for subnet (default id 1).
|
||||||
|
|
||||||
|
.PARAMETER DiscoverSubnet
|
||||||
|
Controls if new hosts should be discovered for new host scans.
|
||||||
|
|
||||||
|
.PARAMETER IsFull
|
||||||
|
Marks subnet as used.
|
||||||
|
|
||||||
|
.PARAMETER TagId
|
||||||
|
Assignes state (tag) to subnet (default: 1 Used).
|
||||||
|
|
||||||
|
.PARAMETER Threshold
|
||||||
|
Subnet threshold.
|
||||||
|
|
||||||
|
.PARAMETER LocationId
|
||||||
|
Location index.
|
||||||
|
#>
|
||||||
|
[OutputType([PS.IPAM.Subnetwork])]
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="CIDR of subnet in dotted format (e.g 10.10.10.0/24)",Position=0)]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0
|
||||||
|
)]
|
||||||
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
|
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]
|
[string]
|
||||||
$CIDR,
|
$CIDR,
|
||||||
[parameter(Mandatory=$true,HelpMessage="Section identifier",Position=1)]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=1
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$SectionId,
|
$SectionId,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Subnet description",Position=2)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=2
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]
|
[string]
|
||||||
$Description,
|
$Description,
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VLAN",Position=3)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=3
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$VlanId,
|
$VlanId,
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VRF",Position=4)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=4
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$VrfId,
|
$VrfId,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Master subnet id for nested subnet",Position=5)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=5
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$MasterSubnetId,
|
$MasterSubnetId,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Id of nameserver to attach to subnet",Position=6)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=6
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$NameserverId,
|
$NameserverId,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu",Position=7)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=7
|
||||||
|
)]
|
||||||
[switch]
|
[switch]
|
||||||
$ShowName,
|
$ShowName,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Controls if PTR records should be created for subnet",Position=8)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=8
|
||||||
|
)]
|
||||||
[switch]
|
[switch]
|
||||||
$DNSRecursive,
|
$DNSRecursive,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Controls weather hostname DNS records are displayed",Position=9)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=9
|
||||||
|
)]
|
||||||
[switch]
|
[switch]
|
||||||
$DNSRecords,
|
$DNSRecords,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Controls if IP requests are allowed for subnet",Position=10)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=10
|
||||||
|
)]
|
||||||
[switch]
|
[switch]
|
||||||
$AllowRequests,
|
$AllowRequests,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Controls which scanagent to use for subnet (default id 1)",Position=11)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=11
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$ScanAgentId,
|
$ScanAgentId,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Controls if new hosts should be discovered for new host scans",Position=12)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=12
|
||||||
|
)]
|
||||||
[switch]
|
[switch]
|
||||||
$DiscoverSubnet,
|
$DiscoverSubnet,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Marks subnet as used",Position=12)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=12
|
||||||
|
)]
|
||||||
[switch]
|
[switch]
|
||||||
$IsFull,
|
$IsFull,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Assignes state (tag) to subnet (default: 1 Used)",Position=12)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=12
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$TagId,
|
$TagId,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Subnet threshold",Position=13)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=13
|
||||||
|
)]
|
||||||
[ValidateScript({ $_ -le 100 -and $_ -ge 1 })]
|
[ValidateScript({ $_ -le 100 -and $_ -ge 1 })]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$Threshold,
|
$Threshold,
|
||||||
[parameter(Mandatory=$false,HelpMessage="Location index",Position=14)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=14
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$LocationId,
|
$LocationId,
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=15
|
||||||
|
)]
|
||||||
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
|
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
$CustomFields
|
$CustomFields
|
||||||
)
|
)
|
||||||
process {
|
process {
|
||||||
$_params = @{
|
$_params = @{
|
||||||
Controller = "subnets"
|
Controller = [PS.IPAM.controllers]::subnets
|
||||||
Method = "POST"
|
Method = "POST"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,10 +246,7 @@ function New-Subnet {
|
|||||||
|
|
||||||
if ($CustomFields) {
|
if ($CustomFields) {
|
||||||
if ($CustomFields -is [PSCustomObject]) {
|
if ($CustomFields -is [PSCustomObject]) {
|
||||||
$_customFields = @{};
|
$_customFields = ConvertTo-Hashtable -InputObject $CustomFields
|
||||||
$CustomFields | Get-Member -MemberType *Property | Where-Object {
|
|
||||||
$_customFields.($_.name) = $CustomFields.($_.name)
|
|
||||||
}
|
|
||||||
} else { $_customFields = $CustomFields }
|
} else { $_customFields = $CustomFields }
|
||||||
|
|
||||||
$_body = $_body + $_customFields
|
$_body = $_body + $_customFields
|
||||||
@@ -111,6 +255,7 @@ function New-Subnet {
|
|||||||
$_params.Add("Params",$_body)
|
$_params.Add("Params",$_body)
|
||||||
|
|
||||||
$_result = Invoke-Request @_params
|
$_result = Invoke-Request @_params
|
||||||
|
|
||||||
if ($_result) {
|
if ($_result) {
|
||||||
return Get-Subnet -CIDR $_result
|
return Get-Subnet -CIDR $_result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user