mirror of
https://github.com/benclaussen/NetboxPS.git
synced 2025-12-13 01:42:28 +00:00
Add parameter sets and logic for ID/Query searches
This commit is contained in:
parent
b72684709a
commit
18852aa990
4 changed files with 201 additions and 60 deletions
|
|
@ -96,67 +96,110 @@ function Get-NetboxIPAMPrefix {
|
|||
[CmdletBinding(DefaultParameterSetName = 'Query')]
|
||||
param
|
||||
(
|
||||
[Parameter(ParameterSetName = 'Query',
|
||||
Position = 0)]
|
||||
[string]$Prefix,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Query,
|
||||
|
||||
[uint16[]]$Id,
|
||||
[Parameter(ParameterSetName = 'ByID')]
|
||||
[uint32[]]$Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[object]$Family,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[boolean]$Is_Pool,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Within,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Within_Include,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Contains,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[ValidateRange(0, 127)]
|
||||
[byte]$Mask_Length,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$VRF,
|
||||
|
||||
[uint16]$VRF_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$VRF_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Tenant,
|
||||
|
||||
[uint16]$Tenant_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Tenant_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Site,
|
||||
|
||||
[uint16]$Site_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Site_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Vlan_VId,
|
||||
|
||||
[uint16]$Vlan_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Vlan_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[object]$Status,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Role,
|
||||
|
||||
[uint16]$Role_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Role_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Limit,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Offset,
|
||||
|
||||
[switch]$Raw
|
||||
)
|
||||
|
||||
if ($null -ne $Family) {
|
||||
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily
|
||||
# if ($null -ne $Family) {
|
||||
# $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily
|
||||
# }
|
||||
#
|
||||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
|
||||
# }
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'ById' {
|
||||
foreach ($Prefix_ID in $Id) {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
default {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -ne $Status) {
|
||||
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
|
||||
}
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
|
|
@ -41,28 +41,56 @@ function Get-NetboxIPAMRole {
|
|||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(ParameterSetName = 'Query',
|
||||
Position = 0)]
|
||||
[string]$Name,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Query,
|
||||
|
||||
[uint16[]]$Id,
|
||||
[Parameter(ParameterSetName = 'ByID')]
|
||||
[uint32[]]$Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Slug,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[switch]$Brief,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Limit,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Offset,
|
||||
|
||||
[switch]$Raw
|
||||
)
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'ById' {
|
||||
foreach ($Role_ID in $Id) {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles', $Role_ID))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
default {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,56 +16,96 @@ function Get-NetboxIPAMVLAN {
|
|||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(ParameterSetName = 'Query',
|
||||
Position = 0)]
|
||||
[ValidateRange(1, 4096)]
|
||||
[uint16]$VID,
|
||||
|
||||
[uint16[]]$Id,
|
||||
[Parameter(ParameterSetName = 'ByID')]
|
||||
[uint32[]]$Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Query,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Name,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Tenant,
|
||||
|
||||
[uint16]$Tenant_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Tenant_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$TenantGroup,
|
||||
|
||||
[uint16]$TenantGroup_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$TenantGroup_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[object]$Status,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Region,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Site,
|
||||
|
||||
[uint16]$Site_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Site_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Group,
|
||||
|
||||
[uint16]$Group_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Group_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Role,
|
||||
|
||||
[uint16]$Role_Id,
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint32]$Role_Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Limit,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Offset,
|
||||
|
||||
[switch]$Raw
|
||||
)
|
||||
|
||||
if ($null -ne $Status) {
|
||||
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
|
||||
# if ($null -ne $Status) {
|
||||
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
|
||||
# }
|
||||
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'ById' {
|
||||
foreach ($VLAN_ID in $Id) {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_ID))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
default {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,17 +23,17 @@ function Get-NetboxTenant {
|
|||
.PARAMETER Name
|
||||
The specific name of the tenant. Must match exactly as is defined in Netbox
|
||||
|
||||
.PARAMETER Slug
|
||||
The specific slug of the tenant. Must match exactly as is defined in Netbox
|
||||
|
||||
.PARAMETER Id
|
||||
The database ID of the tenant
|
||||
|
||||
.PARAMETER Query
|
||||
A standard search query that will match one or more tenants.
|
||||
|
||||
.PARAMETER Slug
|
||||
The specific slug of the tenant. Must match exactly as is defined in Netbox
|
||||
|
||||
.PARAMETER Group
|
||||
The specific group as defined in Netbox.
|
||||
The specific group as defined in Netbox.
|
||||
|
||||
.PARAMETER GroupID
|
||||
The database ID of the group in Netbox
|
||||
|
|
@ -51,41 +51,71 @@ function Get-NetboxTenant {
|
|||
Return the unparsed data from the HTTP request
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\> Get-NetboxTenant
|
||||
PS C:\> Get-NetboxTenant
|
||||
|
||||
.NOTES
|
||||
Additional information about the function.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(DefaultParameterSetName = 'Query')]
|
||||
param
|
||||
(
|
||||
[Parameter(ParameterSetName = 'Query',
|
||||
Position = 0)]
|
||||
[string]$Name,
|
||||
|
||||
[string]$Slug,
|
||||
|
||||
[uint16[]]$Id,
|
||||
[Parameter(ParameterSetName = 'ByID')]
|
||||
[uint32[]]$Id,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Query,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Slug,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[string]$Group,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$GroupID,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[hashtable]$CustomFields,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Limit,
|
||||
|
||||
[Parameter(ParameterSetName = 'Query')]
|
||||
[uint16]$Offset,
|
||||
|
||||
[switch]$Raw
|
||||
)
|
||||
|
||||
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'ById' {
|
||||
foreach ($Tenant_ID in $Id) {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants', $Tenant_ID))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
default {
|
||||
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
|
||||
|
||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
||||
|
||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
||||
|
||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue