Initial commit
This commit is contained in:
172
functions/public/New-PSIPAMFirstFreeIP.ps1
Normal file
172
functions/public/New-PSIPAMFirstFreeIP.ps1
Normal 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
|
||||
Reference in New Issue
Block a user