From 7f856b1d09964b6eb2d017462a309aa9eead8be9 Mon Sep 17 00:00:00 2001 From: Arnike Date: Fri, 30 Dec 2022 14:43:46 +0300 Subject: [PATCH] New address in subnet by subnet object --- functions/public/New-Address.ps1 | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/functions/public/New-Address.ps1 b/functions/public/New-Address.ps1 index e7953bc..c014829 100644 --- a/functions/public/New-Address.ps1 +++ b/functions/public/New-Address.ps1 @@ -47,16 +47,28 @@ function New-Address { Port. #> [OutputType([PS.IPAM.address])] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName="BySubnetId")] param ( [parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, - Position=0)] + Position=0, + ParameterSetName="BySubnetId" + )] [ValidateNotNullOrEmpty()] [int] $SubnetId, + [Parameter( + Mandatory=$true, + ValueFromPipeline=$true, + ValueFromPipelineByPropertyName=$true, + Position=0, + ParameterSetName="BySubnetObject" + )] + [ValidateNotNullOrEmpty()] + [ps.ipam.subnetwork] + $SubnetObject, [parameter( Mandatory=$true, ValueFromPipeline=$true, @@ -175,8 +187,19 @@ function New-Address { Method = "POST" } + switch ($PSCmdlet.ParameterSetName) { + "BySubnetId" { + $_subnetId = $SubnetId + break + } + "BySubnetObject" { + $_subnetId = $SubnetObject.id + break + } + } + $_body = @{ - subnetId = $SubnetId + subnetId = $_subnetId ip = $Ip } if ($Gateway) { $_body.Add("is_gateway", "1") }