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')]
|
[CmdletBinding(DefaultParameterSetName = 'Query')]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
|
[Parameter(ParameterSetName = 'Query',
|
||||||
|
Position = 0)]
|
||||||
[string]$Prefix,
|
[string]$Prefix,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Query,
|
[string]$Query,
|
||||||
|
|
||||||
[uint16[]]$Id,
|
[Parameter(ParameterSetName = 'ByID')]
|
||||||
|
[uint32[]]$Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[object]$Family,
|
[object]$Family,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[boolean]$Is_Pool,
|
[boolean]$Is_Pool,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Within,
|
[string]$Within,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Within_Include,
|
[string]$Within_Include,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Contains,
|
[string]$Contains,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[ValidateRange(0, 127)]
|
[ValidateRange(0, 127)]
|
||||||
[byte]$Mask_Length,
|
[byte]$Mask_Length,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$VRF,
|
[string]$VRF,
|
||||||
|
|
||||||
[uint16]$VRF_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$VRF_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Tenant,
|
[string]$Tenant,
|
||||||
|
|
||||||
[uint16]$Tenant_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Tenant_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Site,
|
[string]$Site,
|
||||||
|
|
||||||
[uint16]$Site_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Site_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Vlan_VId,
|
[string]$Vlan_VId,
|
||||||
|
|
||||||
[uint16]$Vlan_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Vlan_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[object]$Status,
|
[object]$Status,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Role,
|
[string]$Role,
|
||||||
|
|
||||||
[uint16]$Role_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Role_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Limit,
|
[uint16]$Limit,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Offset,
|
[uint16]$Offset,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
)
|
)
|
||||||
|
|
||||||
if ($null -ne $Family) {
|
# if ($null -ne $Family) {
|
||||||
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily
|
# $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()]
|
[CmdletBinding()]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
|
[Parameter(ParameterSetName = 'Query',
|
||||||
|
Position = 0)]
|
||||||
[string]$Name,
|
[string]$Name,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Query,
|
[string]$Query,
|
||||||
|
|
||||||
[uint16[]]$Id,
|
[Parameter(ParameterSetName = 'ByID')]
|
||||||
|
[uint32[]]$Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Slug,
|
[string]$Slug,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[switch]$Brief,
|
[switch]$Brief,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Limit,
|
[uint16]$Limit,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Offset,
|
[uint16]$Offset,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
)
|
)
|
||||||
|
|
||||||
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles'))
|
switch ($PSCmdlet.ParameterSetName) {
|
||||||
|
'ById' {
|
||||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
foreach ($Role_ID in $Id) {
|
||||||
|
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles', $Role_ID))
|
||||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
|
||||||
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
|
||||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
|
||||||
|
$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()]
|
[CmdletBinding()]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
|
[Parameter(ParameterSetName = 'Query',
|
||||||
|
Position = 0)]
|
||||||
|
[ValidateRange(1, 4096)]
|
||||||
[uint16]$VID,
|
[uint16]$VID,
|
||||||
|
|
||||||
[uint16[]]$Id,
|
[Parameter(ParameterSetName = 'ByID')]
|
||||||
|
[uint32[]]$Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Query,
|
[string]$Query,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Name,
|
[string]$Name,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Tenant,
|
[string]$Tenant,
|
||||||
|
|
||||||
[uint16]$Tenant_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Tenant_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$TenantGroup,
|
[string]$TenantGroup,
|
||||||
|
|
||||||
[uint16]$TenantGroup_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$TenantGroup_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[object]$Status,
|
[object]$Status,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Region,
|
[string]$Region,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Site,
|
[string]$Site,
|
||||||
|
|
||||||
[uint16]$Site_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Site_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Group,
|
[string]$Group,
|
||||||
|
|
||||||
[uint16]$Group_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Group_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Role,
|
[string]$Role,
|
||||||
|
|
||||||
[uint16]$Role_Id,
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[uint32]$Role_Id,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Limit,
|
[uint16]$Limit,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Offset,
|
[uint16]$Offset,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
)
|
)
|
||||||
|
|
||||||
if ($null -ne $Status) {
|
# if ($null -ne $Status) {
|
||||||
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
|
# $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
|
.PARAMETER Name
|
||||||
The specific name of the tenant. Must match exactly as is defined in Netbox
|
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
|
.PARAMETER Id
|
||||||
The database ID of the tenant
|
The database ID of the tenant
|
||||||
|
|
||||||
.PARAMETER Query
|
.PARAMETER Query
|
||||||
A standard search query that will match one or more tenants.
|
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
|
.PARAMETER Group
|
||||||
The specific group as defined in Netbox.
|
The specific group as defined in Netbox.
|
||||||
|
|
||||||
.PARAMETER GroupID
|
.PARAMETER GroupID
|
||||||
The database ID of the group in Netbox
|
The database ID of the group in Netbox
|
||||||
|
|
@ -51,41 +51,71 @@ function Get-NetboxTenant {
|
||||||
Return the unparsed data from the HTTP request
|
Return the unparsed data from the HTTP request
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-NetboxTenant
|
PS C:\> Get-NetboxTenant
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
Additional information about the function.
|
Additional information about the function.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding(DefaultParameterSetName = 'Query')]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
|
[Parameter(ParameterSetName = 'Query',
|
||||||
|
Position = 0)]
|
||||||
[string]$Name,
|
[string]$Name,
|
||||||
|
|
||||||
[string]$Slug,
|
[Parameter(ParameterSetName = 'ByID')]
|
||||||
|
[uint32[]]$Id,
|
||||||
[uint16[]]$Id,
|
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Query,
|
[string]$Query,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
|
[string]$Slug,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[string]$Group,
|
[string]$Group,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$GroupID,
|
[uint16]$GroupID,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[hashtable]$CustomFields,
|
[hashtable]$CustomFields,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Limit,
|
[uint16]$Limit,
|
||||||
|
|
||||||
|
[Parameter(ParameterSetName = 'Query')]
|
||||||
[uint16]$Offset,
|
[uint16]$Offset,
|
||||||
|
|
||||||
[switch]$Raw
|
[switch]$Raw
|
||||||
)
|
)
|
||||||
|
|
||||||
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
|
switch ($PSCmdlet.ParameterSetName) {
|
||||||
|
'ById' {
|
||||||
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
|
foreach ($Tenant_ID in $Id) {
|
||||||
|
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants', $Tenant_ID))
|
||||||
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
|
|
||||||
|
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
|
||||||
InvokeNetboxRequest -URI $uri -Raw:$Raw
|
|
||||||
|
$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