202 lines
7.1 KiB
PowerShell
202 lines
7.1 KiB
PowerShell
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 |