Public/Get-DuneIpAddress.ps1
|
function Get-DuneIpAddress { [CmdletBinding(DefaultParameterSetName = "Default")] param ( [Parameter(Position = 0)] [string]$Address, [Parameter()] [string]$Name, [Parameter(ParameterSetName = "Id")] [guid]$Id, [Parameter(ParameterSetName = "ExtId")] [string]$ExtId, [Parameter(ParameterSetName = "Subnet", ValueFromPipeline)] [DuneSubnet]$Subnet, [Parameter(ParameterSetName = "ResourceId")] [guid]$ResourceId, [Parameter(ParameterSetName = "Resource", ValueFromPipeline)] [DuneResource]$Resource, [Parameter()][ValidateSet("v4", "v6")] [string]$Version, [Parameter()] [switch]$Raw, [Parameter()] [switch]$IncludeDeleted ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $ReturnObjects = @() $ProcessedUrls = @() $BaseUri = "ipaddresses" $Method = "GET" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" # Build Uri $Uri = switch ($PSCmdlet.ParameterSetName) { 'Id' { $BaseUri, $Id -join '/' } 'ExtId' { '{0}?ExtIdIEquals={1}' -f $BaseUri, $ExtId } 'Resource' { $BaseUri, "ResourceId=$($Resource.Id)" -join '?' } 'ResourceId' { $BaseUri, "ResourceId=$($ResourceId)" -join '?' } 'Subnet' { $BaseUri, "SubnetId=$($Subnet.Id)" -join '?' } Default { $BaseUri } } if ($Name) { $Uri = $Uri | Add-UriQueryParam "NameILike=$Name" -ConvertWildcards } if ($Address) { $Uri = $Uri | Add-UriQueryParam "AddressLike=$Address" -ConvertWildcards } if ($Version) { $Uri = $Uri | Add-UriQueryParam "Version=$Version" } if ($IncludeDeleted) { $Uri = $Uri | Add-UriQueryParam "IncludeDeleted=1" } # ApiCall Cache if ($ProcessedUrls -notcontains $Uri) { try { # ApiCall and Object conversion $ResultItems = Invoke-DuneApiRequest -Uri $Uri -Method $Method -ExtractItems $ProcessedUrls += $Uri $ReturnObjects += $ResultItems | ForEach-Object { if ($Raw) { $_ } else { ConvertTo-DuneClassObject -Class DuneIpAddress -InputObject $_ } } } catch { throw $_ } } else { Write-Debug "$($MyInvocation.MyCommand)|process|ApiCall Cache hit: DuneApiRequest for $Uri already invoked" } } end { Write-Debug "$($MyInvocation.MyCommand)|end" return $ReturnObjects } } |