Initial commit
This commit is contained in:
70
functions/public/Get-PSIPAMAddress.ps1
Normal file
70
functions/public/Get-PSIPAMAddress.ps1
Normal file
@@ -0,0 +1,70 @@
|
||||
function Get-PSIPAMAddress {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
param (
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Id,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByIP")]
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="BySubnetId")]
|
||||
[ValidateScript({[ipaddress] $_})]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$IP,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByHostName")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$HostName,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByTag")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$TagId,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetId")]
|
||||
[ValidateScript({ $_ -match "^\d+$" })]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$SubnetId,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetCIDR")]
|
||||
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$SubnetCIDR
|
||||
)
|
||||
process {
|
||||
[string[]]$visiblePropertiesList = @('Id','Ip','Hostname','Description')
|
||||
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
|
||||
|
||||
$_params = @{
|
||||
Controller = "addresses"
|
||||
Method = "GET"
|
||||
}
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
"ByID" { $_identifiers = @($id) }
|
||||
"ByIP" { $_identifiers = ("search",$IP) }
|
||||
"ByHostName" { $_identifiers = ("search_hostname",$HostName) }
|
||||
"ByTag" { $_identifiers = ("tags",$TagId,"addresses") }
|
||||
"BySubnetId" {
|
||||
if ($IP) {
|
||||
$_identifiers = ($IP,$SubnetId)
|
||||
} else {
|
||||
$_params.Item("Controller") = "subnets"
|
||||
$_identifiers = ($SubnetId,"addresses")
|
||||
}
|
||||
}
|
||||
"BySubnetCIDR" {
|
||||
$_params.Item("Controller") = "subnets"
|
||||
$_subnetId = (Get-PSIPAMSubnet -CIDR $SubnetCIDR).id
|
||||
if (!$_subnetId) { throw "Cannot find subnet!" }
|
||||
|
||||
$_identifiers = ($_subnetId,"addresses")
|
||||
}
|
||||
}
|
||||
$_params.Add("Identifiers",$_identifiers)
|
||||
|
||||
Invoke-PSIPAMRequest @_params | `
|
||||
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function Get-PSIPAMAddress
|
||||
Reference in New Issue
Block a user