Fixes, added session class
This commit is contained in:
@@ -1,127 +1,61 @@
|
||||
function Set-Address {
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(DefaultParameterSetName="ById")]
|
||||
param (
|
||||
[parameter(
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Id of subnet address belongs to",
|
||||
Position=0)]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Id of subnet address belongs to",Position=0,ParameterSetName="ById")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Defines if address is presented as gateway",
|
||||
Position=1)]
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PS.IPAM.Address]
|
||||
$AddressObject,
|
||||
[parameter(Mandatory=$false,HelpMessage="Defines if address is presented as gateway",Position=1)]
|
||||
[bool]
|
||||
$Gateway,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Address description",
|
||||
Position=2)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Address description",Position=2)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Description,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Address hostname",
|
||||
Position=3)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Address hostname",Position=3)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Hostname,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Mac address",
|
||||
Position=4)]
|
||||
[parameter(Mandatory=$false,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)]
|
||||
[parameter(Mandatory=$false,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+$" })]
|
||||
[parameter(Mandatory=$false,HelpMessage="Id of subnet address belongs to",Position=6)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$TagId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Controls if PTR should not be created",
|
||||
Position=7)]
|
||||
[parameter(Mandatory=$false,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+$" })]
|
||||
[parameter(Mandatory=$false,HelpMessage="Id of PowerDNS PTR record",Position=8)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$PTRId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Note",
|
||||
Position=9)]
|
||||
[parameter(Mandatory=$false,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)]
|
||||
[parameter(Mandatory=$false,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+$" })]
|
||||
[parameter(Mandatory=$false,HelpMessage="Id of device address belongs to",Position=11)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
[int]
|
||||
$DeviceId,
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
HelpMessage="Port",
|
||||
Position=12)]
|
||||
[parameter(Mandatory=$false,HelpMessage="Port",Position=12)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Port,
|
||||
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
|
||||
[parameter(Mandatory=$false)]
|
||||
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
|
||||
$CustomFields
|
||||
)
|
||||
@@ -130,21 +64,25 @@ function Set-Address {
|
||||
Controller = "addresses"
|
||||
Method = "PATCH"
|
||||
}
|
||||
$_identifiers = @($Id)
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"ByID" { $_id = $Id;break }
|
||||
"ByAddressObject" { $_id = $AddressObject.id;break }
|
||||
}
|
||||
$_identifiers = @($_id)
|
||||
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
$_body = @{ }
|
||||
if ($Gateway) { $_body.Add("is_gateway", [int]$Gateway) }
|
||||
if ($Gateway) { $_body.Add("is_gateway", $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 ($PTRIgnore) { $_body.Add("PTRignore", $PTRIgnore) }
|
||||
if ($PTRId) { $_body.add("PTR", $PTRId)}
|
||||
if ($Note) { $_body.Add("note", $Note) }
|
||||
if ($ExcludePing) { $_body.Add("excludePing", [int]$ExcludePing) }
|
||||
if ($ExcludePing) { $_body.Add("excludePing", $ExcludePing) }
|
||||
if ($DeviceId) { $_body.Add("deviceId", $DeviceId) }
|
||||
if ($Port) { $_body.Add("port", $Port) }
|
||||
|
||||
@@ -165,7 +103,7 @@ function Set-Address {
|
||||
Invoke-Request @_params
|
||||
}
|
||||
finally {
|
||||
Get-Address -Id $Id
|
||||
Get-Address -Id $_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user