Version 1.3.0 (#3)

* Add `OPTIONS` method validation

* Remove parameter validation as workaround for CHOICES API endpoint until further testing

* Add help block for Get-NetboxTenant

* SkipConnectedCheck for Get-NetboxAPIDefinition

* Correct help block for New-NetboxIPAMAddress

* Add parameter position 0 for 'Address' in Get-NetboxIPAMAddress

* Allow pipeline input for Address parameter in New-NetboxIPAMAddress

* Update parameter types

* Add parameter sets and logic for ID/Query searches

* Add Get-NetboxDCIMSite

* Update psproj

* Update deploy.ps1

* Move Get-NetboxCircuit

* Add Circuit cmdlets
- New-NetboxCircuit
- Get-NetboxCircuitProvider
- Get-NetboxCircuitTermination
- Get-NetboxCircuitType

* Update deploy script output path

* Update Set-NetboxIPAMAddress
- Replace Interface parameter with Assigned_Object_Type and Assigned_Object_Id
- Add validation logic for Assigned_Object_ parameters
- Change Status parameter to string

* Add Get-ModelDefinition function

* Update psproj

* Update deploy.ps1 variables

* Update exported files

* Remove references to `_choices` API calls

* Add Postman collection

* Add Postman collection

* Update deploy.ps1

* Add Set-NetboxIPAMPrefix function

* Increment version to 1.3.0

Co-authored-by: Ben Claussen <claussen@neonet.org>
This commit is contained in:
Ben Claussen 2021-03-25 16:52:08 -04:00 committed by GitHub
parent 55510e5f03
commit cfb53cf933
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 3991 additions and 2033 deletions

View file

@ -0,0 +1,131 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:15
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuit.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuit {
<#
.SYNOPSIS
Gets one or more circuits
.DESCRIPTION
A detailed description of the Get-NetboxCircuit function.
.PARAMETER Id
Database ID of circuit. This will query for exactly the IDs provided
.PARAMETER CID
Circuit ID
.PARAMETER InstallDate
Date of installation
.PARAMETER CommitRate
Committed rate in Kbps
.PARAMETER Query
A raw search query... As if you were searching the web site
.PARAMETER Provider
The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs
.PARAMETER Type
Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs
.PARAMETER Site
Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs
.PARAMETER Tenant
Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs
.PARAMETER Limit
A description of the Limit parameter.
.PARAMETER Offset
A description of the Offset parameter.
.PARAMETER Raw
A description of the Raw parameter.
.PARAMETER ID__IN
Multiple unique DB IDs to retrieve
.EXAMPLE
PS C:\> Get-NetboxCircuit
.NOTES
Additional information about the function.
#>
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$CID,
[Parameter(ParameterSetName = 'Query')]
[datetime]$InstallDate,
[Parameter(ParameterSetName = 'Query')]
[uint32]$CommitRate,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[object]$Provider,
[Parameter(ParameterSetName = 'Query')]
[object]$Type,
[Parameter(ParameterSetName = 'Query')]
[string]$Site,
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}

View file

@ -0,0 +1,67 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-11-04 11:48
Created by: Claussen
Organization: NEOnet
Filename: New-NetboxCircuit.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function New-NetboxCircuit {
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[string]$CID,
[Parameter(Mandatory = $true)]
[uint32]$Provider,
[Parameter(Mandatory = $true)]
[uint32]$Type,
#[ValidateSet('Active', 'Planned', 'Provisioning', 'Offline', 'Deprovisioning', 'Decommissioned ')]
[uint16]$Status = 'Active',
[string]$Description,
[uint32]$Tenant,
[string]$Termination_A,
[datetime]$Install_Date,
[string]$Termination_Z,
[ValidateRange(0, 2147483647)]
[uint32]$Commit_Rate,
[string]$Comments,
[hashtable]$Custom_Fields,
[switch]$Force,
[switch]$Raw
)
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$Method = 'POST'
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}

View file

@ -1,83 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:15
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuit.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuit {
<#
.SYNOPSIS
Gets one or more circuits
.DESCRIPTION
A detailed description of the Get-NetboxCircuit function.
.PARAMETER CID
Circuit ID
.PARAMETER InstallDate
Date of installation
.PARAMETER CommitRate
Committed rate in Kbps
.PARAMETER Query
A raw search query... As if you were searching the web site
.PARAMETER Provider
The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs
.PARAMETER Type
Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs
.PARAMETER Site
Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs
.PARAMETER Tenant
Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs
.PARAMETER Id
Database ID of circuit. This will query for exactly the IDs provided
.PARAMETER ID__IN
Multiple unique DB IDs to retrieve
.EXAMPLE
PS C:\> Get-NetboxCircuit
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[string]$CID,
[datetime]$InstallDate,
[uint32]$CommitRate,
[string]$Query,
[object]$Provider,
[object]$Type,
[string]$Site,
[string]$Tenant,
[uint16[]]$Id
)
#TODO: Place script here
}

View file

@ -1,38 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:15
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuitsChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuitsChoices {
<#
.SYNOPSIS
Gets the choices associated with circuits
.DESCRIPTION
A detailed description of the Get-NetboxCircuitsChoices function.
.EXAMPLE
PS C:\> Get-NetboxCircuitsChoices
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('circuits', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}

View file

@ -0,0 +1,72 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-11-04 12:06
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuitProvider.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuitProvider {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById',
Mandatory = $true)]
[uint16[]]$Id,
[Parameter(ParameterSetName = 'Query',
Mandatory = $false)]
[string]$Name,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
[Parameter(ParameterSetName = 'Query')]
[string]$ASN,
[Parameter(ParameterSetName = 'Query')]
[string]$Account,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}

View file

@ -0,0 +1,79 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-11-04 10:22
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuitTermination.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuitTermination {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById',
ValueFromPipelineByPropertyName = $true)]
[uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Circuit_ID,
[Parameter(ParameterSetName = 'Query')]
[string]$Term_Side,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Port_Speed,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[string]$Site_ID,
[Parameter(ParameterSetName = 'Query')]
[string]$Site,
[Parameter(ParameterSetName = 'Query')]
[string]$XConnect_ID,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
process {
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}
}

View file

@ -0,0 +1,64 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-11-04 12:34
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxCircuitType.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxCircuitType {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Name,
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit_types', $i))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-types'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}

View file

@ -64,21 +64,21 @@ function New-NetboxDCIMDevice {
)
#endregion Parameters
if ($null -ne $Device_Role) {
# Validate device role?
}
if ($null -ne $Device_Type) {
# Validate device type?
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
if ($null -ne $Face) {
$PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
}
# if ($null -ne $Device_Role) {
# # Validate device role?
# }
#
# if ($null -ne $Device_Type) {
# # Validate device type?
# }
#
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# }
#
# if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# }
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))

View file

@ -64,13 +64,13 @@ function Set-NetboxDCIMDevice {
)
begin {
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
if ($null -ne $Face) {
$PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
}
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# }
#
# if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# }
}
process {

View file

@ -1,25 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/23/2020 12:13
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('dcim', '_choices'))
$uri = BuildNewURI -Segments $uriSegments -Parameters $Parameters
InvokeNetboxRequest -URI $uri
}

View file

@ -47,9 +47,9 @@ function Add-NetboxDCIMInterface {
[uint16[]]$Tagged_VLANs
)
if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
# if ($null -ne $Form_Factor) {
# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
# }
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {

View file

@ -50,9 +50,9 @@ function Set-NetboxDCIMInterface {
)
begin {
if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
# if ($null -ne $Form_Factor) {
# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
# }
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {

View file

@ -60,9 +60,9 @@ function Set-NetboxDCIMInterfaceConnection {
)
begin {
if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
}
# if ($null -ne $Connection_Status) {
# $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
# }
if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) {
throw "Cannot set multiple connections to the same interface"

View file

@ -0,0 +1,108 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-10-02 15:52
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxDCIMSite.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxDCIMSite {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true)]
[uint32]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Name,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
[Parameter(ParameterSetName = 'Query')]
[string]$Facility,
[Parameter(ParameterSetName = 'Query')]
[uint32]$ASN,
[Parameter(ParameterSetName = 'Query')]
[decimal]$Latitude,
[Parameter(ParameterSetName = 'Query')]
[decimal]$Longitude,
[Parameter(ParameterSetName = 'Query')]
[string]$Contact_Name,
[Parameter(ParameterSetName = 'Query')]
[string]$Contact_Phone,
[Parameter(ParameterSetName = 'Query')]
[string]$Contact_Email,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Group_ID,
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant_Group,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_ID,
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant,
[Parameter(ParameterSetName = 'Query')]
[string]$Status,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Region_ID,
[Parameter(ParameterSetName = 'Query')]
[string]$Region,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($Site_ID in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites'))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}

View file

@ -1,102 +0,0 @@
function ValidateDCIMChoice {
<#
.SYNOPSIS
Internal function to validate provided values for static choices
.DESCRIPTION
When users connect to the API, choices for each major object are cached to the config variable.
These values are then utilized to validate if the provided value from a user is valid.
.PARAMETER ProvidedValue
The value to validate against static choices
.PARAMETER PowerConnectionStatus
Validate against power connection status values
.PARAMETER InterfaceTemplateFormFactor
Validate against interface template form factor values
.PARAMETER InterfaceConnectionStatus
Validate against interface connection status values
.PARAMETER InterfaceFormFactor
Validate against interface form factor values
.PARAMETER ConsolePortConnectionStatus
Validate against console port connection status values
.PARAMETER DeviceStatus
Validate against device status values
.PARAMETER DeviceFace
Validate against device face values
.PARAMETER RackType
Validate against rack type values
.PARAMETER RackWidth
Validate against rack width values.
.EXAMPLE
PS C:\> ValidateDCIMChoice -ProvidedValue 'rear' -DeviceFace
.EXAMPLE
PS C:\> ValidateDCIMChoice -ProvidedValue 'middle' -DeviceFace
>> Invalid value middle for device:face. Must be one of: 0, 1, Front, Rear
.OUTPUTS
This function returns the integer value if valid. Otherwise, it will throw an error.
.NOTES
Additional information about the function.
.FUNCTIONALITY
This cmdlet is intended to be used internally and not exposed to the user
#>
[CmdletBinding()]
[OutputType([uint16])]
param
(
[Parameter(Mandatory = $true)]
[object]$ProvidedValue,
[Parameter(ParameterSetName = 'power-port:connection_status',
Mandatory = $true)]
[switch]$PowerConnectionStatus,
[Parameter(ParameterSetName = 'interface-template:form_factor',
Mandatory = $true)]
[switch]$InterfaceTemplateFormFactor,
[Parameter(ParameterSetName = 'interface-connection:connection_status',
Mandatory = $true)]
[switch]$InterfaceConnectionStatus,
[Parameter(ParameterSetName = 'interface:form_factor',
Mandatory = $true)]
[switch]$InterfaceFormFactor,
[Parameter(ParameterSetName = 'console-port:connection_status',
Mandatory = $true)]
[switch]$ConsolePortConnectionStatus,
[Parameter(ParameterSetName = 'device:status',
Mandatory = $true)]
[switch]$DeviceStatus,
[Parameter(ParameterSetName = 'device:face',
Mandatory = $true)]
[switch]$DeviceFace,
[Parameter(ParameterSetName = 'rack:type',
Mandatory = $true)]
[switch]$RackType,
[Parameter(ParameterSetName = 'rack:width',
Mandatory = $true)]
[switch]$RackWidth
)
ValidateChoice -MajorObject 'DCIM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue
}

View file

@ -1,11 +0,0 @@
function Get-NetboxExtrasChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('extras', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}

View file

@ -0,0 +1,64 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-11-04 14:23
Created by: Claussen
Organization: NEOnet
Filename: Get-ModelDefinition.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-ModelDefinition {
[CmdletBinding(DefaultParameterSetName = 'ByName')]
param
(
[Parameter(ParameterSetName = 'ByName',
Mandatory = $true)]
[string]$ModelName,
[Parameter(ParameterSetName = 'ByPath',
Mandatory = $true)]
[string]$URIPath,
[Parameter(ParameterSetName = 'ByPath')]
[string]$Method = "post"
)
switch ($PsCmdlet.ParameterSetName) {
'ByName' {
$script:NetboxConfig.APIDefinition.definitions.$ModelName
break
}
'ByPath' {
switch ($Method) {
"get" {
break
}
"post" {
if (-not $URIPath.StartsWith('/')) {
$URIPath = "/$URIPath"
}
if (-not $URIPath.EndsWith('/')) {
$URIPath = "$URIPath/"
}
$ModelName = $script:NetboxConfig.APIDefinition.paths.$URIPath.post.parameters.schema.'$ref'.split('/')[-1]
$script:NetboxConfig.APIDefinition.definitions.$ModelName
break
}
}
break
}
}
}

View file

@ -1,41 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/26/2020 14:23
Created by: Claussen
Organization: NEOnet
Filename: GetChoiceValidValues.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function GetChoiceValidValues {
[CmdletBinding()]
[OutputType([System.Collections.ArrayList])]
param
(
[Parameter(Mandatory = $true)]
[string]$MajorObject,
[Parameter(Mandatory = $true)]
[object]$Choice
)
$ValidValues = New-Object System.Collections.ArrayList
if (-not $script:NetboxConfig.Choices.$MajorObject.$Choice) {
throw "Missing choices for $Choice"
}
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.$MajorObject.$Choice.value)
[void]$ValidValues.AddRange($script:NetboxConfig.Choices.$MajorObject.$Choice.label)
if ($ValidValues.Count -eq 0) {
throw "Missing valid values for $MajorObject.$Choice"
}
return [System.Collections.ArrayList]$ValidValues
}

View file

@ -27,7 +27,7 @@ function InvokeNetboxRequest {
[ValidateRange(0, 60)]
[uint16]$Timeout = 5,
[ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', IgnoreCase = $true)]
[ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS', IgnoreCase = $true)]
[string]$Method = 'GET',
[switch]$Raw

View file

@ -1,76 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/26/2020 14:23
Created by: Claussen
Organization: NEOnet
Filename: ValidateChoice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function ValidateChoice {
[CmdletBinding()]
[OutputType([uint16], [string], [bool])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Circuits', 'DCIM', 'Extras', 'IPAM', 'Virtualization', IgnoreCase = $true)]
[string]$MajorObject,
[Parameter(Mandatory = $true)]
[string]$ChoiceName,
[Parameter(Mandatory = $true)]
[object]$ProvidedValue
)
$ValidValues = GetChoiceValidValues -MajorObject $MajorObject -Choice $ChoiceName
Write-Verbose "Validating $ChoiceName"
Write-Verbose "Checking '$ProvidedValue' against [$($ValidValues -join ', ')]"
# Coercing everything to strings for matching...
# some values are integers, some are strings, some are booleans
# Join the valid values with a pipe as a delimeter, because some values have spaces
if (([string]($ValidValues -join '|') -split '\|') -inotcontains [string]$ProvidedValue) {
throw "Invalid value '$ProvidedValue' for '$ChoiceName'. Must be one of: $($ValidValues -join ', ')"
}
switch -wildcard ("$MajorObject/$ChoiceName") {
"Circuits" {
# This has things that are not integers
}
"DCIM/*connection_status" {
# This has true/false values instead of integers
try {
$val = [bool]::Parse($ProvidedValue)
} catch {
# It must not be a true/false value
$val = $script:NetboxConfig.Choices.$MajorObject.$ChoiceName.Where({
$_.Label -eq $ProvidedValue
}).Value
}
return $val
}
default {
# Convert the ProvidedValue to the integer value
try {
$intVal = [uint16]"$ProvidedValue"
} catch {
# It must not be a number, get the value from the label
$intVal = [uint16]$script:NetboxConfig.Choices.$MajorObject.$ChoiceName.Where({
$_.Label -eq $ProvidedValue
}).Value
}
return $intVal
}
}
}

View file

@ -1,60 +1,84 @@
function Get-NetboxIPAMAddress {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Address,
[uint16[]]$Id,
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[object]$Family,
[uint16]$Parent,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Parent,
[Parameter(ParameterSetName = 'Query')]
[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]$Device,
[uint16]$Device_ID,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Device_ID,
[Parameter(ParameterSetName = 'Query')]
[string]$Virtual_Machine,
[uint16]$Virtual_Machine_Id,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Virtual_Machine_Id,
[uint16]$Interface_Id,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Interface_Id,
[Parameter(ParameterSetName = 'Query')]
[object]$Status,
[Parameter(ParameterSetName = 'Query')]
[object]$Role,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -IPAddressFamily
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($IP_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IP_ID))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
}
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
break
}
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
@ -62,4 +86,8 @@
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}

View file

@ -47,6 +47,9 @@ function New-NetboxIPAMAddress {
.PARAMETER Description
Description of IP address
.PARAMETER Force
Do not prompt for confirmation to create IP.
.PARAMETER Raw
Return raw results from API service
@ -57,11 +60,13 @@ function New-NetboxIPAMAddress {
Additional information about the function.
#>
[CmdletBinding()]
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[string]$Address,
[object]$Status = 'Active',
@ -80,20 +85,35 @@ function New-NetboxIPAMAddress {
[string]$Description,
[switch]$Force,
[switch]$Raw
)
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST'
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
$segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
# foreach ($Property in $EnumProperties.Keys) {
# if ($PSBoundParameters.ContainsKey($Property)) {
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
# }
# }
#
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
if ($Force -or $PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}

View file

@ -43,9 +43,6 @@ function Remove-NetboxIPAMAddress {
[switch]$Force
)
begin {
}
process {
foreach ($IPId in $Id) {
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
@ -59,7 +56,4 @@ function Remove-NetboxIPAMAddress {
}
}
}
end {
}
}

View file

@ -23,7 +23,7 @@ function Set-NetboxIPAMAddress {
[string]$Address,
[object]$Status,
[string]$Status,
[uint16]$Tenant,
@ -35,7 +35,10 @@ function Set-NetboxIPAMAddress {
[hashtable]$Custom_Fields,
[uint16]$Interface,
[ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
[uint16]$Assigned_Object_Id,
[string]$Description,
@ -43,20 +46,39 @@ function Set-NetboxIPAMAddress {
)
begin {
if ($Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -IPAddressStatus
}
if ($Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
# Write-Verbose "Validating enum properties"
# $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0))
$Method = 'PATCH'
#
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
# foreach ($Property in $EnumProperties.Keys) {
# if ($PSBoundParameters.ContainsKey($Property)) {
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
# } else {
# Write-Verbose "User did not provide a value for [$Property]"
# }
# }
#
# Write-Verbose "Finished enum validation"
}
process {
foreach ($IPId in $Id) {
if ($PSBoundParameters.ContainsKey('Assigned_Object_Type') -or $PSBoundParameters.ContainsKey('Assigned_Object_Id')) {
if ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) {
throw "Assigned_Object_Type is required when specifying Assigned_Object_Id"
} elseif ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) {
throw "Assigned_Object_Id is required when specifying Assigned_Object_Type"
}
}
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
Write-Verbose "Obtaining IPs from ID $IPId"
Write-Verbose "Obtaining IP from ID $IPId"
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentIP.Address, 'Set')) {
@ -64,11 +86,8 @@ function Set-NetboxIPAMAddress {
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
}
}
}
end {
}
}

View file

@ -13,37 +13,67 @@
function Get-NetboxIPAMAggregate {
[CmdletBinding()]
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[uint16]$Limit,
[uint16]$Offset,
[object]$Family,
[datetime]$Date_Added,
[uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'ByID')]
[uint16[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Prefix,
[Parameter(ParameterSetName = 'Query')]
[object]$Family,
[Parameter(ParameterSetName = 'Query')]
[uint16]$RIR_Id,
[Parameter(ParameterSetName = 'Query')]
[string]$RIR,
[Parameter(ParameterSetName = 'Query')]
[datetime]$Date_Added,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
if ($null -ne $Family) {
$PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily
}
# if ($null -ne $Family) {
# $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily
# }
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($IP_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates', $IP_ID))
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
$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', 'aggregates'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}

View file

@ -1,25 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:54
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxIPAMChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxIPAMChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('ipam', '_choices'))
$uri = BuildNewURI -Segments $uriSegments -Parameters $Parameters
InvokeNetboxRequest -URI $uri
}

View file

@ -93,65 +93,104 @@ function Get-NetboxIPAMPrefix {
Additional information about the function.
#>
[CmdletBinding()]
[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
}
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
break
}
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
@ -159,4 +198,8 @@ function Get-NetboxIPAMPrefix {
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}

View file

@ -40,7 +40,7 @@ function New-NetboxIPAMPrefix {
[switch]$Raw
)
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
<#
# As of 2018/10/18, this does not appear to be a validated IPAM choice

View file

@ -0,0 +1,92 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2021 v5.8.186
Created on: 2021-03-23 13:54
Created by: Claussen
Organization: NEOnet
Filename: Set-NetboxIPAMPrefix.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Set-NetboxIPAMPrefix {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
[string]$Prefix,
[string]$Status,
[uint16]$Tenant,
[uint16]$Site,
[uint16]$VRF,
[uint16]$VLAN,
[object]$Role,
[hashtable]$Custom_Fields,
[string]$Description,
[switch]$Is_Pool,
[switch]$Force
)
begin {
# Write-Verbose "Validating enum properties"
# $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0))
$Method = 'PATCH'
#
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
# foreach ($Property in $EnumProperties.Keys) {
# if ($PSBoundParameters.ContainsKey($Property)) {
# Write-Verbose "Validating property [$Property] with value [$($PSBoundParameters.$Property)]"
# $PSBoundParameters.$Property = ValidateValue -ModelDefinition $ModelDefinition -Property $Property -ProvidedValue $PSBoundParameters.$Property
# } else {
# Write-Verbose "User did not provide a value for [$Property]"
# }
# }
#
# Write-Verbose "Finished enum validation"
}
process {
foreach ($PrefixId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId))
Write-Verbose "Obtaining Prefix from ID $PrefixId"
$CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop
if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
}
}
}
}

View file

@ -41,23 +41,47 @@ function Get-NetboxIPAMRole {
[CmdletBinding()]
param
(
[uint16[]]$Id,
[string]$Query,
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Name,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[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
)
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
@ -65,4 +89,8 @@ function Get-NetboxIPAMRole {
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}

View file

@ -16,49 +16,85 @@ function Get-NetboxIPAMVLAN {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[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
@ -66,6 +102,10 @@ function Get-NetboxIPAMVLAN {
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}

View file

@ -63,11 +63,11 @@
[switch]$Raw
)
$PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
}
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
#
# if ($null -ne $Role) {
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
# }
$segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))

View file

@ -1,109 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:54
Created by: Claussen
Organization: NEOnet
Filename: ValidateIPAMChoice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function ValidateIPAMChoice {
<#
.SYNOPSIS
Internal function to verify provided values for static choices
.DESCRIPTION
When users connect to the API, choices for each major object are cached to the config variable.
These values are then utilized to verify if the provided value from a user is valid.
.PARAMETER ProvidedValue
The value to validate against static choices
.PARAMETER AggregateFamily
Verify against aggregate family values
.PARAMETER PrefixFamily
Verify against prefix family values
.PARAMETER PrefixStatus
Verify against prefix status values
.PARAMETER IPAddressFamily
Verify against ip-address family values
.PARAMETER IPAddressStatus
Verify against ip-address status values
.PARAMETER IPAddressRole
Verify against ip-address role values
.PARAMETER VLANStatus
Verify against VLAN status values
.PARAMETER ServiceProtocol
Verify against service protocol values
.EXAMPLE
PS C:\> ValidateIPAMChoice -ProvidedValue 'loopback' -IPAddressRole
.EXAMPLE
PS C:\> ValidateIPAMChoice -ProvidedValue 'Loopback' -IPAddressFamily
>> Invalid value Loopback for ip-address:family. Must be one of: 4, 6, IPv4, IPv6
.OUTPUTS
This function returns the integer value if valid. Otherwise, it will throw an error.
.NOTES
Additional information about the function.
.FUNCTIONALITY
This cmdlet is intended to be used internally and not exposed to the user
#>
[CmdletBinding(DefaultParameterSetName = 'service:protocol')]
[OutputType([uint16])]
param
(
[Parameter(Mandatory = $true)]
[object]$ProvidedValue,
[Parameter(ParameterSetName = 'aggregate:family',
Mandatory = $true)]
[switch]$AggregateFamily,
[Parameter(ParameterSetName = 'prefix:family',
Mandatory = $true)]
[switch]$PrefixFamily,
[Parameter(ParameterSetName = 'prefix:status',
Mandatory = $true)]
[switch]$PrefixStatus,
[Parameter(ParameterSetName = 'ip-address:family',
Mandatory = $true)]
[switch]$IPAddressFamily,
[Parameter(ParameterSetName = 'ip-address:status',
Mandatory = $true)]
[switch]$IPAddressStatus,
[Parameter(ParameterSetName = 'ip-address:role',
Mandatory = $true)]
[switch]$IPAddressRole,
[Parameter(ParameterSetName = 'vlan:status',
Mandatory = $true)]
[switch]$VLANStatus,
[Parameter(ParameterSetName = 'service:protocol',
Mandatory = $true)]
[switch]$ServiceProtocol
)
ValidateChoice -MajorObject 'IPAM' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue
}

View file

@ -48,8 +48,6 @@
try {
Write-Verbose "Verifying API connectivity..."
$null = VerifyAPIConnectivity
$script:NetboxConfig.Connected = $true
Write-Verbose "Successfully connected!"
} catch {
Write-Verbose "Failed to connect. Generating error"
Write-Verbose $_.Exception.Message
@ -60,14 +58,25 @@
}
}
Write-Verbose "Caching static choices"
$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices
$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet
$script:NetboxConfig.Choices.Extras = Get-NetboxExtrasChoices
$script:NetboxConfig.Choices.IPAM = Get-NetboxIPAMChoices
#$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet
#$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices
$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices
Write-Verbose "Caching API definition"
$script:NetboxConfig.APIDefinition = Get-NetboxAPIDefinition
if ([version]$script:NetboxConfig.APIDefinition.info.version -lt 2.8) {
$Script:NetboxConfig.Connected = $false
throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.APIDefinition.info.version)"
}
$script:NetboxConfig.Connected = $true
Write-Verbose "Successfully connected!"
#Write-Verbose "Caching static choices"
#$script:NetboxConfig.Choices.Circuits = Get-NetboxCircuitsChoices
#$script:NetboxConfig.Choices.DCIM = Get-NetboxDCIMChoices # Not completed yet
#$script:NetboxConfig.Choices.Extras = Get-NetboxExtrasChoices
#$script:NetboxConfig.Choices.IPAM = Get-NetboxIPAMChoices
##$script:NetboxConfig.Choices.Secrets = Get-NetboxSecretsChoices # Not completed yet
##$script:NetboxConfig.Choices.Tenancy = Get-NetboxTenancyChoices
#$script:NetboxConfig.Choices.Virtualization = Get-NetboxVirtualizationChoices
Write-Verbose "Connection process completed"
}

View file

@ -0,0 +1,29 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174
Created on: 4/28/2020 11:57
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxAPIDefinition.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxAPIDefinition {
[CmdletBinding()]
param ()
#$URI = "https://netbox.neonet.org/api/docs/?format=openapi"
$Segments = [System.Collections.ArrayList]::new(@('docs'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi'}
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
InvokeNetboxRequest -URI $URI -Timeout 10
}

View file

@ -12,6 +12,7 @@
'Connected' = $false
'Choices' = @{
}
'APIDefinition' = $null
}
}

View file

@ -2,9 +2,9 @@
[CmdletBinding()]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('extras', '_choices'))
$uriSegments = [System.Collections.ArrayList]::new(@('extras'))
$uri = BuildNewURI -Segments $uriSegments -SkipConnectedCheck
$uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json'} -SkipConnectedCheck
InvokeNetboxRequest -URI $uri
}

View file

@ -1,25 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 11:56
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxTenancyChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxTenancyChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('tenancy', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}

View file

@ -13,28 +13,100 @@
function Get-NetboxTenant {
[CmdletBinding()]
<#
.SYNOPSIS
Get a tenent from Netbox
.DESCRIPTION
A detailed description of the Get-NetboxTenant function.
.PARAMETER Name
The specific name 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.
.PARAMETER GroupID
The database ID of the group in Netbox
.PARAMETER CustomFields
Hashtable in the format @{"field_name" = "value"} to search
.PARAMETER Limit
Limit the number of results to this number
.PARAMETER Offset
Start the search at this index in results
.PARAMETER Raw
Return the unparsed data from the HTTP request
.EXAMPLE
PS C:\> Get-NetboxTenant
.NOTES
Additional information about the function.
#>
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Name,
[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
)
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
@ -42,4 +114,8 @@ function Get-NetboxTenant {
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}

View file

@ -1,25 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 14:10
Created by: Claussen
Organization: NEOnet
Filename: Get-NetboxVirtualizationChoices.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function Get-NetboxVirtualizationChoices {
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification = "These are literally 'choices' in Netbox")]
param ()
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', '_choices'))
$uri = BuildNewURI -Segments $uriSegments
InvokeNetboxRequest -URI $uri
}

View file

@ -1,76 +0,0 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.172
Created on: 3/19/2020 14:12
Created by: Claussen
Organization: NEOnet
Filename: ValidateVirtualizationChoice.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
function ValidateVirtualizationChoice {
<#
.SYNOPSIS
Internal function to verify provided values for static choices
.DESCRIPTION
When users connect to the API, choices for each major object are cached to the config variable.
These values are then utilized to verify if the provided value from a user is valid.
.PARAMETER ProvidedValue
The value to validate against static choices
.PARAMETER AggregateFamily
Verify against aggregate family values
.PARAMETER PrefixFamily
Verify against prefix family values
.PARAMETER PrefixStatus
Verify against prefix status values
.PARAMETER IPAddressFamily
Verify against ip-address family values
.PARAMETER IPAddressStatus
Verify against ip-address status values
.PARAMETER IPAddressRole
Verify against ip-address role values
.PARAMETER VLANStatus
Verify against VLAN status values
.PARAMETER ServiceProtocol
Verify against service protocol values
.EXAMPLE
PS C:\> VerifyIPAMChoices -ProvidedValue 'loopback' -IPAddressRole
.EXAMPLE
PS C:\> VerifyIPAMChoices -ProvidedValue 'Loopback' -IPAddressFamily
>> Invalid value Loopback for ip-address:family. Must be one of: 4, 6, IPv4, IPv6
.FUNCTIONALITY
This cmdlet is intended to be used internally and not exposed to the user
.OUTPUT
This function returns nothing if the value is valid. Otherwise, it will throw an error.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[object]$ProvidedValue,
[Parameter(ParameterSetName = 'virtual-machine:status',
Mandatory = $true)]
[switch]$VirtualMachineStatus
)
ValidateChoice -MajorObject 'Virtualization' -ChoiceName $PSCmdlet.ParameterSetName -ProvidedValue $ProvidedValue
}

View file

@ -46,7 +46,14 @@ function New-NetboxVirtualMachine {
[string]$Comments
)
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
#
# # Validate the status against the APIDefinition
# if ($ModelDefinition.properties.status.enum -inotcontains $Status) {
# throw ("Invalid value [] for Status. Must be one of []" -f $Status, ($ModelDefinition.properties.status.enum -join ', '))
# }
#
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
@ -56,3 +63,7 @@ function New-NetboxVirtualMachine {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
}

View file

@ -50,19 +50,19 @@ function Set-NetboxVirtualMachine {
[switch]$Force
)
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
}
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# }
#
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
Write-Verbose "Obtaining VM from ID $Id"
$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop
#$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop
Write-Verbose "Finished obtaining VM"
if ($Force -or $pscmdlet.ShouldProcess($CurrentVM.Name, "Set")) {
if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
$URI = BuildNewURI -Segments $URIComponents.Segments

View file

@ -60,15 +60,13 @@ function Get-NetboxVirtualMachineInterface {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[Parameter(ValueFromPipeline = $true)]
[uint16]$Id,
[string]$Name,
[string]$Query,
[boolean]$Enabled,
[uint16]$MTU,
@ -79,6 +77,10 @@ function Get-NetboxVirtualMachineInterface {
[string]$MAC_Address,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw
)

View file

@ -66,16 +66,11 @@ function Get-NetboxVirtualizationCluster {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[string]$Name,
[Alias('q')]
[string]$Query,
[string]$Name,
[Alias('id__in')]
[uint16[]]$Id,
[string]$Group,
@ -90,36 +85,18 @@ function Get-NetboxVirtualizationCluster {
[uint16]$Site_Id,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw
)
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters'))
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters'))
$URIParameters = @{
}
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
if ($CmdletParameterName -eq 'Id') {
# Check if there is one or more values for Id and build a URI or query as appropriate
if (@($PSBoundParameters[$CmdletParameterName]).Count -gt 1) {
$URIParameters['id__in'] = $Id -join ','
} else {
[void]$uriSegments.Add($PSBoundParameters[$CmdletParameterName])
}
} elseif ($CmdletParameterName -eq 'Query') {
$URIParameters['q'] = $PSBoundParameters[$CmdletParameterName]
} else {
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -16,33 +16,28 @@ function Get-NetboxVirtualizationClusterGroup {
[CmdletBinding()]
param
(
[uint16]$Limit,
[uint16]$Offset,
[string]$Name,
[string]$Slug,
[string]$Description,
[string]$Query,
[uint32[]]$Id,
[uint16]$Limit,
[uint16]$Offset,
[switch]$Raw
)
$uriSegments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups'))
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups'))
$URIParameters = @{
}
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
foreach ($CmdletParameterName in $PSBoundParameters.Keys) {
if ($CmdletParameterName -in $CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping parameter $CmdletParameterName"
continue
}
$URIParameters[$CmdletParameterName.ToLower()] = $PSBoundParameters[$CmdletParameterName]
}
$uri = BuildNewURI -Segments $uriSegments -Parameters $URIParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}

View file

@ -1,106 +1,101 @@
<#
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
Created on: 2/28/2018 11:04 AM
Created by: Ben Claussen
Organization: NEOnet
Filename: NetboxPS.psd1
-------------------------------------------------------------------------
Module Manifest
-------------------------------------------------------------------------
Module Name: NetboxPS
===========================================================================
#>
#
# Module manifest for module 'NetboxPS'
#
# Generated by: Ben Claussen
#
# Generated on: 2021-03-25
#
@{
# Script module or binary module file associated with this manifest
RootModule = 'NetboxPS.psm1'
# Script module or binary module file associated with this manifest.
RootModule = 'NetboxPS.psm1'
# Version number of this module.
ModuleVersion = '1.0.4'
# Version number of this module.
ModuleVersion = '1.3.0'
# ID used to uniquely identify this module
GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896'
# Supported PSEditions
# CompatiblePSEditions = @()
# Author of this module
Author = 'Ben Claussen'
# ID used to uniquely identify this module
GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896'
# Company or vendor of this module
CompanyName = 'NEOnet'
# Author of this module
Author = 'Ben Claussen'
# Copyright statement for this module
Copyright = '(c) 2018. All rights reserved.'
# Company or vendor of this module
CompanyName = 'NEOnet'
# Description of the functionality provided by this module
Description = 'A Powershell wrapper for Netbox API'
# Copyright statement for this module
Copyright = '(c) 2018. All rights reserved.'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'
# Description of the functionality provided by this module
Description = 'A Powershell wrapper for Netbox API'
# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'
# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = ''
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = '2.0'
# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = '2.0.50727'
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
DotNetFrameworkVersion = '2.0'
# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = 'None'
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
CLRVersion = '2.0.50727'
# Modules that must be imported into the global environment prior to importing
# this module
RequiredModules = @()
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @('System.Web')
# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()
# Script files (.ps1) that are run in the caller's environment prior to
# importing this module
ScriptsToProcess = @()
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = 'System.Web'
# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# Modules to import as nested modules of the module specified in
# ModuleToProcess
NestedModules = @()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()
# Functions to export from this module
FunctionsToExport = @('*') #For performanace, list functions explicity
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @()
# Cmdlets to export from this module
CmdletsToExport = '*'
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'
# Aliases to export from this module
AliasesToExport = '*' #For performanace, list alias explicity
# Variables to export from this module
VariablesToExport = '*'
# List of all modules packaged with this module
ModuleList = @()
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = '*'
# List of all files packaged with this module
FileList = @()
# DSC resources to export from this module
# DscResourcesToExport = @()
# Private data to pass to the module specified in ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
# List of all modules packaged with this module
# ModuleList = @()
# List of all files packaged with this module
# FileList = @()
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
#Support for PowerShellGet galleries.
PSData = @{
# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('Netbox', 'API', 'DCIM', 'IPAM')
Tags = 'Netbox','API','DCIM','IPAM'
# A URL to the license for this module.
# LicenseUri = ''
@ -114,14 +109,24 @@
# ReleaseNotes of this module
# ReleaseNotes = ''
# Prerelease string of this module
# Prerelease = ''
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false
# External dependent modules of this module
# ExternalModuleDependencies = @()
} # End of PSData hashtable
} # End of PrivateData hashtable
# HelpInfo URI of this module
# HelpInfoURI = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}

View file

@ -18,5 +18,5 @@ $script:CommonParameterNames = New-Object System.Collections.ArrayList
SetupNetboxConfigVariable
#Export-ModuleMember -Function *
Export-ModuleMember -Function *-*
Export-ModuleMember -Function *
#Export-ModuleMember -Function *-*

View file

@ -5,7 +5,6 @@
<Folders>
<Folder>Functions</Folder>
<Folder>Functions\DCIM</Folder>
<Folder>Functions\Extras</Folder>
<Folder>Functions\Circuits</Folder>
<Folder>Functions\Virtualization</Folder>
<Folder>Functions\IPAM</Folder>
@ -24,6 +23,11 @@
<Folder>Functions\Setup</Folder>
<Folder>Functions\Setup\Support</Folder>
<Folder>Tests</Folder>
<Folder>Functions\DCIM\Sites</Folder>
<Folder>Functions\Circuits\Circuits</Folder>
<Folder>Functions\Circuits\Providers</Folder>
<Folder>Functions\Circuits\Types</Folder>
<Folder>Functions\Circuits\Terminations</Folder>
</Folders>
<Files>
<File Build="2">NetboxPS.psd1</File>
@ -42,8 +46,6 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-CheckNetboxIsConnected_ps1" ExportFunctions="True">Functions\Helpers\CheckNetboxIsConnected.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-BuildNewURI_ps1" ExportFunctions="True">Functions\Helpers\BuildNewURI.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-BuildURIComponents_ps1" ExportFunctions="True">Functions\Helpers\BuildURIComponents.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-GetChoiceValidValues_ps1" ExportFunctions="True">Functions\Helpers\GetChoiceValidValues.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-ValidateChoice_ps1" ExportFunctions="True">Functions\Helpers\ValidateChoice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-GetNetboxAPIErrorBody_ps1" ExportFunctions="True">Functions\Helpers\GetNetboxAPIErrorBody.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-InvokeNetboxRequest_ps1" ExportFunctions="True">Functions\Helpers\InvokeNetboxRequest.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-ThrowNetboxRESTError_ps1" ExportFunctions="True">Functions\Helpers\ThrowNetboxRESTError.ps1</File>
@ -56,8 +58,6 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxCredential_ps1" ExportFunctions="True">Functions\Setup\Set-NetboxCredential.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCredential_ps1" ExportFunctions="True">Functions\Setup\Get-NetboxCredential.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Connect-NetboxAPI_ps1" ExportFunctions="True">Functions\Setup\Connect-NetboxAPI.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxExtrasChoices_ps1" ExportFunctions="True">Functions\Extras\Get-NetboxExtrasChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-ValidateDCIMChoice_ps1" ExportFunctions="False">Functions\DCIM\ValidateDCIMChoice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMVLAN_ps1" ExportFunctions="True">Functions\IPAM\VLAN\Get-NetboxIPAMVLAN.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxIPAMVLAN_ps1" ExportFunctions="True">Functions\IPAM\VLAN\New-NetboxIPAMVLAN.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMRole_ps1" ExportFunctions="True">Functions\IPAM\Role\Get-NetboxIPAMRole.ps1</File>
@ -69,10 +69,7 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxIPAMPrefix_ps1" ExportFunctions="True">Functions\IPAM\Prefix\New-NetboxIPAMPrefix.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxIPAMAddress_ps1" ExportFunctions="True">Functions\IPAM\Address\Remove-NetboxIPAMAddress.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxIPAMAddress_ps1" ExportFunctions="True">Functions\IPAM\Address\Set-NetboxIPAMAddress.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-ValidateIPAMChoice_ps1" ExportFunctions="True">Functions\IPAM\ValidateIPAMChoice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxIPAMChoices_ps1" ExportFunctions="True">Functions\IPAM\Get-NetboxIPAMChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxTenant_ps1" ExportFunctions="True">Functions\Tenancy\Get-NetboxTenant.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxTenancyChoices_ps1" ExportFunctions="True">Functions\Tenancy\Get-NetboxTenancyChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualMachine_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachine\Get-NetboxVirtualMachine.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxVirtualMachine_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachine\New-NetboxVirtualMachine.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxVirtualMachine_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachine\Set-NetboxVirtualMachine.ps1</File>
@ -80,10 +77,8 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-Add-NetboxVirtualMachineInterface_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachineInterface\Add-NetboxVirtualMachineInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualMachineInterface_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachineInterface\Get-NetboxVirtualMachineInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxVirtualMachineInterface_ps1" ExportFunctions="True">Functions\Virtualization\VirtualMachineInterface\Set-NetboxVirtualMachineInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualizationChoices_ps1" ExportFunctions="True">Functions\Virtualization\Get-NetboxVirtualizationChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualizationCluster_ps1" ExportFunctions="True">Functions\Virtualization\VirtualizationCluster\Get-NetboxVirtualizationCluster.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxVirtualizationClusterGroup_ps1" ExportFunctions="True">Functions\Virtualization\VirtualizationCluster\Get-NetboxVirtualizationClusterGroup.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-ValidateVirtualizationChoice_ps1" ExportFunctions="True">Functions\Virtualization\ValidateVirtualizationChoice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMDevice_ps1" ExportFunctions="True">Functions\DCIM\Devices\Get-NetboxDCIMDevice.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMDeviceType_ps1" ExportFunctions="True">Functions\DCIM\Devices\Get-NetboxDCIMDeviceType.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMDeviceRole_ps1" ExportFunctions="True">Functions\DCIM\Devices\Get-NetboxDCIMDeviceRole.ps1</File>
@ -99,10 +94,16 @@
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxDCIMInterface_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Remove-NetboxDCIMInterface.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Remove-NetboxDCIMInterfaceConnection_ps1" ExportFunctions="True">Functions\DCIM\Interfaces\Remove-NetboxDCIMInterfaceConnection.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMPlatform_ps1" ExportFunctions="True">Functions\DCIM\Get-NetboxDCIMPlatform.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMChoices_ps1" ExportFunctions="True">Functions\DCIM\Get-NetboxDCIMChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuitsChoices_ps1" ExportFunctions="True">Functions\Circuits\Get-NetboxCircuitsChoices.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuit_ps1" ExportFunctions="True">Functions\Circuits\Get-NetboxCircuit.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuit_ps1" ExportFunctions="True">Functions\Circuits\Circuits\Get-NetboxCircuit.ps1</File>
<File Build="2" Shared="True" ReferenceFunction="Invoke-deploy_ps1" ExportFunctions="False">deploy.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxAPIDefinition_ps1" ExportFunctions="True">Functions\Setup\Support\Get-NetboxAPIDefinition.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxDCIMSite_ps1" ExportFunctions="True">Functions\DCIM\Sites\Get-NetboxDCIMSite.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuitTermination_ps1" ExportFunctions="True">Functions\Circuits\Terminations\Get-NetboxCircuitTermination.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-New-NetboxCircuit_ps1" ExportFunctions="True">Functions\Circuits\Circuits\New-NetboxCircuit.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuitProvider_ps1" ExportFunctions="True">Functions\Circuits\Providers\Get-NetboxCircuitProvider.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-NetboxCircuitType_ps1" ExportFunctions="True">Functions\Circuits\Types\Get-NetboxCircuitType.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Get-ModelDefinition_ps1" ExportFunctions="True">Functions\Helpers\Get-ModelDefinition.ps1</File>
<File Build="0" Shared="True" ReferenceFunction="Invoke-Set-NetboxIPAMPrefix_ps1" ExportFunctions="True">Functions\IPAM\Prefix\Set-NetboxIPAMPrefix.ps1</File>
</Files>
<StartupScript>R:\Netbox\NetboxPS\Test-Module.ps1</StartupScript>
</Project>

132
NetboxPS/NetboxPS.psd1 Normal file
View file

@ -0,0 +1,132 @@
#
# Module manifest for module 'NetboxPS'
#
# Generated by: Ben Claussen
#
# Generated on: 2021-03-25
#
@{
# Script module or binary module file associated with this manifest.
RootModule = 'NetboxPS.psm1'
# Version number of this module.
ModuleVersion = '1.3.0'
# Supported PSEditions
# CompatiblePSEditions = @()
# ID used to uniquely identify this module
GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896'
# Author of this module
Author = 'Ben Claussen'
# Company or vendor of this module
CompanyName = 'NEOnet'
# Copyright statement for this module
Copyright = '(c) 2018. All rights reserved.'
# Description of the functionality provided by this module
Description = 'A Powershell wrapper for Netbox API'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
DotNetFrameworkVersion = '2.0'
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
CLRVersion = '2.0.50727'
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = 'System.Web'
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @()
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = '*'
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = '*'
# DSC resources to export from this module
# DscResourcesToExport = @()
# List of all modules packaged with this module
# ModuleList = @()
# List of all files packaged with this module
# FileList = @()
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
PSData = @{
# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'Netbox','API','DCIM','IPAM'
# A URL to the license for this module.
# LicenseUri = ''
# A URL to the main website for this project.
ProjectUri = 'https://github.com/benclaussen/NetboxPS'
# A URL to an icon representing this module.
# IconUri = ''
# ReleaseNotes of this module
# ReleaseNotes = ''
# Prerelease string of this module
# Prerelease = ''
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false
# External dependent modules of this module
# ExternalModuleDependencies = @()
} # End of PSData hashtable
} # End of PrivateData hashtable
# HelpInfo URI of this module
# HelpInfoURI = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,19 @@
<#
.SYNOPSIS
A brief description of the Invoke-deploy_ps1 file.
.DESCRIPTION
A description of the file.
.PARAMETER SkipVersion
A description of the SkipVersion parameter.
.PARAMETER VersionIncrease
A description of the VersionIncrease parameter.
.PARAMETER NewVersion
A description of the NewVersion parameter.
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.174
@ -7,39 +22,111 @@
Organization: NEOnet
Filename: deploy.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
[CmdletBinding(DefaultParameterSetName = 'IncreaseVersion')]
param
(
[Parameter(ParameterSetName = 'SkipVersion')]
[switch]$SkipVersion,
[Parameter(ParameterSetName = 'IncreaseVersion')]
[version]$VersionIncrease = "0.0.1",
[Parameter(ParameterSetName = 'SetVersion')]
[version]$NewVersion
)
Import-Module "Microsoft.PowerShell.Utility" -ErrorAction Stop
Write-Host "Beginning deployment" -ForegroundColor Green
$PS1Files = Get-ChildItem "$PSScriptRoot\Functions" -Filter "*.ps1" -Recurse | Sort-Object Name
$ModuleName = 'NetboxPS'
$ConcatenatedFilePath = "$PSScriptRoot\concatenated.ps1"
$FunctionPath = "$PSScriptRoot\Functions"
$OutputDirectory = "$PSScriptRoot\$ModuleName"
$PSD1OutputPath = "$OutputDirectory\$ModuleName.psd1"
$PSM1OutputPath = "$OutputDirectory\$ModuleName.psm1"
"" | Out-File -FilePath .\concatenated.ps1 -Encoding utf8
$PS1Files = Get-ChildItem $FunctionPath -Filter "*.ps1" -Recurse | Sort-Object Name
"" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8
$Counter = 0
Write-Host "Concatenating [$($PS1Files.Count)] PS1 files from $FunctionPath"
foreach ($File in $PS1Files) {
$Counter++
try {
Write-Host (" Adding file {0:D2}/{1:D2}: $($File.Name)" -f $Counter, $PS1Files.Count)
"`r`n#region File $($File.Name)`r`n" | Out-File -FilePath .\concatenated.ps1 -Encoding utf8 -Append
"`r`n#region File $($File.Name)`r`n" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop
Get-Content $File.FullName -Encoding UTF8 | Out-File -FilePath .\concatenated.ps1 -Encoding utf8 -Append
Get-Content $File.FullName -Encoding UTF8 -ErrorAction Stop | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop
"`r`n#endregion" | Out-File -FilePath .\concatenated.ps1 -Encoding utf8 -Append
"`r`n#endregion" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append -ErrorAction Stop
} catch {
Write-Host "FAILED TO WRITE CONCATENATED FILE: $($_.Exception.Message): $($_.TargetObject)" -ForegroundColor Red
return
}
}
"" | Out-File -FilePath .\concatenated.ps1 -Encoding utf8 -Append
"" | Out-File -FilePath $ConcatenatedFilePath -Encoding utf8 -Append
Write-Host " Adding psm1"
Get-Content .\NetboxPS.psm1 | Out-File -FilePath .\concatenated.ps1 -Encoding UTF8 -Append
Get-Content "$PSScriptRoot\$ModuleName.psm1" | Out-File -FilePath $ConcatenatedFilePath -Encoding UTF8 -Append
$PSDManifest = Import-PowerShellDataFile -Path "$PSScriptRoot\$ModuleName.psd1"
# Get the version from the PSD1
#[version]$CurrentVersion = [regex]::matches($PSDContent, "\s*ModuleVersion\s=\s'(\d*.\d*.\d*)'\s*").groups[1].value
[version]$CurrentVersion = $PSDManifest.ModuleVersion
switch ($PSCmdlet.ParameterSetName) {
"SkipVersion" {
# Dont do anything with the PSD
Write-Host " Skipping version update, maintaining version [$CurrentVersion]"
break
}
"IncreaseVersion" {
# Calculate the new version
[version]$NewVersion = "{0}.{1}.{2}" -f ($CurrentVersion.Major + $VersionIncrease.Major), ($CurrentVersion.Minor + $VersionIncrease.Minor), ($CurrentVersion.Build + $VersionIncrease.Build)
Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]"
# Replace the version number in the content
#$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8
Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion
break
}
"SetVersion" {
Write-Host " Updating version in PSD1 from [$CurrentVersion] to [$NewVersion]"
# Replace the version number in the content
#$PSDContent -replace $CurrentVersion, $NewVersion | Out-File $PSScriptRoot\$ModuleName.psd1 -Encoding UTF8
Update-ModuleManifest -Path "$PSScriptRoot\$ModuleName.psd1" -ModuleVersion $NewVersion
break
}
}
if (-not (Test-Path $OutputDirectory)) {
try {
Write-Warning "Creating path [$OutputDirectory]"
$null = New-Item -Path $OutputDirectory -ItemType Directory -Force
} catch {
throw "Failed to create directory [$OutputDirectory]: $($_.Exception.Message)"
}
}
Write-Host " Copying psd1"
Copy-Item -Path .\NetboxPS.psd1 -Destination .\dist\NetboxPS.psd1 -Force
Copy-Item -Path "$PSScriptRoot\$ModuleName.psd1" -Destination $PSD1OutputPath -Force
Write-Host " Copying psm1"
Copy-Item -Path .\concatenated.ps1 -Destination .\dist\NetboxPS.psm1 -Force
Copy-Item -Path $ConcatenatedFilePath -Destination $PSM1OutputPath -Force
Write-Host "Deployment complete" -ForegroundColor Green

127
dist/NetboxPS.psd1 vendored
View file

@ -1,127 +0,0 @@
<#
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.148
Created on: 2/28/2018 11:04 AM
Created by: Ben Claussen
Organization: NEOnet
Filename: NetboxPS.psd1
-------------------------------------------------------------------------
Module Manifest
-------------------------------------------------------------------------
Module Name: NetboxPS
===========================================================================
#>
@{
# Script module or binary module file associated with this manifest
RootModule = 'NetboxPS.psm1'
# Version number of this module.
ModuleVersion = '1.0.4'
# ID used to uniquely identify this module
GUID = 'bba9b06c-49c8-47cf-8358-aca7c4e78896'
# Author of this module
Author = 'Ben Claussen'
# Company or vendor of this module
CompanyName = 'NEOnet'
# Copyright statement for this module
Copyright = '(c) 2018. All rights reserved.'
# Description of the functionality provided by this module
Description = 'A Powershell wrapper for Netbox API'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'
# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = ''
# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = '2.0'
# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = '2.0.50727'
# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = 'None'
# Modules that must be imported into the global environment prior to importing
# this module
RequiredModules = @()
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @('System.Web')
# Script files (.ps1) that are run in the caller's environment prior to
# importing this module
ScriptsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
FormatsToProcess = @()
# Modules to import as nested modules of the module specified in
# ModuleToProcess
NestedModules = @()
# Functions to export from this module
FunctionsToExport = @('*') #For performanace, list functions explicity
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = '*' #For performanace, list alias explicity
# List of all modules packaged with this module
ModuleList = @()
# List of all files packaged with this module
FileList = @()
# Private data to pass to the module specified in ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
#Support for PowerShellGet galleries.
PSData = @{
# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('Netbox', 'API', 'DCIM', 'IPAM')
# A URL to the license for this module.
# LicenseUri = ''
# A URL to the main website for this project.
ProjectUri = 'https://github.com/benclaussen/NetboxPS'
# A URL to an icon representing this module.
# IconUri = ''
# ReleaseNotes of this module
# ReleaseNotes = ''
} # End of PSData hashtable
} # End of PrivateData hashtable
}