tigpas-NetboxPS/NetboxPS/NetboxPS.psm1

5165 lines
127 KiB
PowerShell
Raw Normal View History

2020-12-08 12:00:26 -05:00

#region File Add-NetboxDCIMInterface.ps1
function Add-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[uint16]$Device,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[bool]$Enabled,
2020-12-08 12:00:26 -05:00
[object]$Form_Factor,
2020-12-08 12:00:26 -05:00
[uint16]$MTU,
2020-12-08 12:00:26 -05:00
[string]$MAC_Address,
2020-12-08 12:00:26 -05:00
[bool]$MGMT_Only,
2020-12-08 12:00:26 -05:00
[uint16]$LAG,
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode,
2020-12-08 12:00:26 -05:00
[ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN,
2020-12-08 12:00:26 -05:00
[ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs
)
2020-12-08 12:00:26 -05:00
# if ($null -ne $Form_Factor) {
# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
# }
2020-12-08 12:00:26 -05:00
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {
'Access' {
100
break
}
2020-12-08 12:00:26 -05:00
'Tagged' {
200
break
}
2020-12-08 12:00:26 -05:00
'Tagged All' {
300
break
}
2020-12-08 12:00:26 -05:00
default {
$_
}
}
}
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
#endregion
#region File Add-NetboxDCIMInterfaceConnection.ps1
function Add-NetboxDCIMInterfaceConnection {
2021-07-23 16:19:03 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
Create a new connection between two interfaces
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Create a new connection between two interfaces
2020-12-08 12:00:26 -05:00
.PARAMETER Connection_Status
Is it connected or planned?
2020-12-08 12:00:26 -05:00
.PARAMETER Interface_A
Database ID of interface A
2020-12-08 12:00:26 -05:00
.PARAMETER Interface_B
Database ID of interface B
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Add-NetboxDCIMInterfaceConnection -Interface_A $value1 -Interface_B $value2
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[object]$Connection_Status,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[uint16]$Interface_A,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[uint16]$Interface_B
)
2020-12-08 12:00:26 -05:00
if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
}
2020-12-08 12:00:26 -05:00
# Verify if both Interfaces exist
2021-07-23 16:19:03 -04:00
Get-NetboxDCIMInterface -Id $Interface_A -ErrorAction Stop | Out-null
Get-NetboxDCIMInterface -Id $Interface_B -ErrorAction Stop | Out-null
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
#endregion
#region File Add-NetboxVirtualMachineInterface.ps1
function Add-NetboxVirtualMachineInterface {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[uint16]$Virtual_Machine,
2020-12-08 12:00:26 -05:00
[boolean]$Enabled = $true,
2020-12-08 12:00:26 -05:00
[string]$MAC_Address,
2020-12-08 12:00:26 -05:00
[uint16]$MTU,
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
2020-12-08 12:00:26 -05:00
$PSBoundParameters.Enabled = $Enabled
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Method POST -Body $URIComponents.Parameters
}
#endregion
#region File BuildNewURI.ps1
function BuildNewURI {
<#
.SYNOPSIS
Create a new URI for Netbox
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Internal function used to build a URIBuilder object.
2020-12-08 12:00:26 -05:00
.PARAMETER Hostname
Hostname of the Netbox API
2020-12-08 12:00:26 -05:00
.PARAMETER Segments
Array of strings for each segment in the URL path
2020-12-08 12:00:26 -05:00
.PARAMETER Parameters
Hashtable of query parameters to include
2020-12-08 12:00:26 -05:00
.PARAMETER HTTPS
Whether to use HTTPS or HTTP
2020-12-08 12:00:26 -05:00
.PARAMETER Port
A description of the Port parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER APIInfo
A description of the APIInfo parameter.
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> BuildNewURI
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
[OutputType([System.UriBuilder])]
param
(
[Parameter(Mandatory = $false)]
[string[]]$Segments,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $false)]
[hashtable]$Parameters,
2020-12-08 12:00:26 -05:00
[switch]$SkipConnectedCheck
)
2020-12-08 12:00:26 -05:00
Write-Verbose "Building URI"
2020-12-08 12:00:26 -05:00
if (-not $SkipConnectedCheck) {
# There is no point in continuing if we have not successfully connected to an API
$null = CheckNetboxIsConnected
}
2020-12-08 12:00:26 -05:00
# Begin a URI builder with HTTP/HTTPS and the provided hostname
2021-03-31 10:24:08 -04:00
$uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort)
2020-12-08 12:00:26 -05:00
# Generate the path by trimming excess slashes and whitespace from the $segments[] and joining together
$uriBuilder.Path = "api/{0}/" -f ($Segments.ForEach({
$_.trim('/').trim()
}) -join '/')
2020-12-08 12:00:26 -05:00
Write-Verbose " URIPath: $($uriBuilder.Path)"
2020-12-08 12:00:26 -05:00
if ($parameters) {
# Loop through the parameters and use the HttpUtility to create a Query string
[System.Collections.Specialized.NameValueCollection]$URIParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty)
2020-12-08 12:00:26 -05:00
foreach ($param in $Parameters.GetEnumerator()) {
Write-Verbose " Adding URI parameter $($param.Key):$($param.Value)"
$URIParams[$param.Key] = $param.Value
}
2020-12-08 12:00:26 -05:00
$uriBuilder.Query = $URIParams.ToString()
}
2020-12-08 12:00:26 -05:00
Write-Verbose " Completed building URIBuilder"
# Return the entire UriBuilder object
$uriBuilder
}
#endregion
#region File BuildURIComponents.ps1
function BuildURIComponents {
[CmdletBinding()]
[OutputType([hashtable])]
param
(
[Parameter(Mandatory = $true)]
[System.Collections.ArrayList]$URISegments,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[object]$ParametersDictionary,
2020-12-08 12:00:26 -05:00
[string[]]$SkipParameterByName
)
2020-12-08 12:00:26 -05:00
Write-Verbose "Building URI components"
2020-12-08 12:00:26 -05:00
$URIParameters = @{
}
2020-12-08 12:00:26 -05:00
foreach ($CmdletParameterName in $ParametersDictionary.Keys) {
if ($CmdletParameterName -in $script:CommonParameterNames) {
# These are common parameters and should not be appended to the URI
Write-Debug "Skipping common parameter $CmdletParameterName"
continue
}
2020-12-08 12:00:26 -05:00
if ($CmdletParameterName -in $SkipParameterByName) {
Write-Debug "Skipping parameter $CmdletParameterName by SkipParameterByName"
continue
}
2020-12-08 12:00:26 -05:00
switch ($CmdletParameterName) {
"id" {
# Check if there is one or more values for Id and build a URI or query as appropriate
if (@($ParametersDictionary[$CmdletParameterName]).Count -gt 1) {
Write-Verbose " Joining IDs for parameter"
$URIParameters['id__in'] = $ParametersDictionary[$CmdletParameterName] -join ','
} else {
Write-Verbose " Adding ID to segments"
[void]$uriSegments.Add($ParametersDictionary[$CmdletParameterName])
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
'Query' {
Write-Verbose " Adding query parameter"
$URIParameters['q'] = $ParametersDictionary[$CmdletParameterName]
break
}
2020-12-08 12:00:26 -05:00
'CustomFields' {
Write-Verbose " Adding custom field query parameters"
foreach ($field in $ParametersDictionary[$CmdletParameterName].GetEnumerator()) {
Write-Verbose " Adding parameter 'cf_$($field.Key) = $($field.Value)"
$URIParameters["cf_$($field.Key.ToLower())"] = $field.Value
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
default {
Write-Verbose " Adding $($CmdletParameterName.ToLower()) parameter"
$URIParameters[$CmdletParameterName.ToLower()] = $ParametersDictionary[$CmdletParameterName]
break
}
}
}
2020-12-08 12:00:26 -05:00
return @{
'Segments' = [System.Collections.ArrayList]$URISegments
'Parameters' = $URIParameters
}
}
#endregion
#region File CheckNetboxIsConnected.ps1
function CheckNetboxIsConnected {
[CmdletBinding()]
param ()
2020-12-08 12:00:26 -05:00
Write-Verbose "Checking connection status"
if (-not $script:NetboxConfig.Connected) {
throw "Not connected to a Netbox API! Please run 'Connect-NetboxAPI'"
}
}
2021-03-31 10:24:08 -04:00
#endregion
#region File Clear-NetboxCredential.ps1
function Clear-NetboxCredential {
[CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)]
param
(
[switch]$Force
)
2021-03-31 10:24:08 -04:00
if ($Force -or ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Clear'))) {
$script:NetboxConfig.Credential = $null
}
}
2020-12-08 12:00:26 -05:00
#endregion
#region File Connect-NetboxAPI.ps1
function Connect-NetboxAPI {
<#
.SYNOPSIS
Connects to the Netbox API and ensures Credential work properly
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
.DESCRIPTION
2021-03-31 10:24:08 -04:00
Connects to the Netbox API and ensures Credential work properly
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Hostname
2021-03-31 10:24:08 -04:00
The hostname for the resource such as netbox.domain.com
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Credential
2021-03-31 10:24:08 -04:00
Credential object containing the API key in the password. Username is not applicable
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
.PARAMETER Scheme
Scheme for the URI such as HTTP or HTTPS. Defaults to HTTPS
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
.PARAMETER Port
Port for the resource. Value between 1-65535
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
.PARAMETER URI
The full URI for the resource such as "https://netbox.domain.com:8443"
2021-07-22 11:53:58 -04:00
.PARAMETER SkipCertificateCheck
A description of the SkipCertificateCheck parameter.
.PARAMETER TimeoutSeconds
The number of seconds before the HTTP call times out. Defaults to 30 seconds
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Connect-NetboxAPI -Hostname "netbox.domain.com"
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
This will prompt for Credential, then proceed to attempt a connection to Netbox
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
[CmdletBinding(DefaultParameterSetName = 'Manual')]
2020-12-08 12:00:26 -05:00
param
(
2021-03-31 10:24:08 -04:00
[Parameter(ParameterSetName = 'Manual',
Mandatory = $true)]
2020-12-08 12:00:26 -05:00
[string]$Hostname,
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $false)]
2021-03-31 10:24:08 -04:00
[pscredential]$Credential,
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
[Parameter(ParameterSetName = 'Manual')]
[ValidateSet('https', 'http', IgnoreCase = $true)]
[string]$Scheme = 'https',
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
[Parameter(ParameterSetName = 'Manual')]
[uint16]$Port = 443,
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
[Parameter(ParameterSetName = 'URI',
Mandatory = $true)]
2021-07-22 11:53:58 -04:00
[string]$URI,
[Parameter(Mandatory = $false)]
[switch]$SkipCertificateCheck = $false,
[ValidateNotNullOrEmpty()]
[ValidateRange(1, 65535)]
[uint16]$TimeoutSeconds = 30
2020-12-08 12:00:26 -05:00
)
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
if (-not $Credential) {
try {
$Credential = Get-NetboxCredential -ErrorAction Stop
} catch {
# Credentials are not set... Try to obtain from the user
if (-not ($Credential = Get-Credential -UserName 'username-not-applicable' -Message "Enter token for Netbox")) {
throw "Token is necessary to connect to a Netbox API."
}
}
}
2021-07-22 11:53:58 -04:00
$invokeParams = @{ SkipCertificateCheck = $SkipCertificateCheck; }
if ("Desktop" -eq $PSVersionTable.PsEdition) {
#Remove -SkipCertificateCheck from Invoke Parameter (not supported <= PS 5)
$invokeParams.remove("SkipCertificateCheck")
}
#for PowerShell (<=) 5 (Desktop), Enable TLS 1.1, 1.2 and Disable SSL chain trust
if ("Desktop" -eq $PSVersionTable.PsEdition) {
2022-12-06 13:35:56 -05:00
#Add System.web (Need for ParseQueryString)
Add-Type -AssemblyName System.Web
2021-07-22 11:53:58 -04:00
#Enable TLS 1.1 and 1.2
Set-NetboxCipherSSL
if ($SkipCertificateCheck) {
#Disable SSL chain trust...
Set-NetboxuntrustedSSL
}
}
2021-03-31 10:24:08 -04:00
switch ($PSCmdlet.ParameterSetName) {
'Manual' {
$uriBuilder = [System.UriBuilder]::new($Scheme, $Hostname, $Port)
}
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
'URI' {
$uriBuilder = [System.UriBuilder]::new($URI)
if ([string]::IsNullOrWhiteSpace($uriBuilder.Host)) {
throw "URI appears to be invalid. Must be in format [host.name], [scheme://host.name], or [scheme://host.name:port]"
}
}
}
2021-07-22 11:53:58 -04:00
2021-03-31 10:24:08 -04:00
$null = Set-NetboxHostName -Hostname $uriBuilder.Host
2021-07-22 11:53:58 -04:00
$null = Set-NetboxCredential -Credential $Credential
2021-03-31 10:24:08 -04:00
$null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme
$null = Set-NetboxHostPort -Port $uriBuilder.Port
2021-07-22 11:53:58 -04:00
$null = Set-NetboxInvokeParams -invokeParams $invokeParams
$null = Set-NetboxTimeout -TimeoutSeconds $TimeoutSeconds
2020-12-08 12:00:26 -05:00
try {
Write-Verbose "Verifying API connectivity..."
$null = VerifyAPIConnectivity
} catch {
Write-Verbose "Failed to connect. Generating error"
Write-Verbose $_.Exception.Message
if (($_.Exception.Response) -and ($_.Exception.Response.StatusCode -eq 403)) {
throw "Invalid token"
} else {
throw $_
}
}
2021-07-22 11:53:58 -04:00
# 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)"
# }
Write-Verbose "Checking Netbox version compatibility"
$script:NetboxConfig.NetboxVersion = Get-NetboxVersion
if ([version]$script:NetboxConfig.NetboxVersion.'netbox-version' -lt 2.8) {
2020-12-08 12:00:26 -05:00
$Script:NetboxConfig.Connected = $false
2021-07-22 11:53:58 -04:00
throw "Netbox version is incompatible with this PS module. Requires >=2.8.*, found version $($script:NetboxConfig.NetboxVersion.'netbox-version')"
} else {
Write-Verbose "Found compatible version [$($script:NetboxConfig.NetboxVersion.'netbox-version')]!"
2020-12-08 12:00:26 -05:00
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$script:NetboxConfig.Connected = $true
Write-Verbose "Successfully connected!"
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
#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
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
Write-Verbose "Connection process completed"
}
#endregion
#region File CreateEnum.ps1
function CreateEnum {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$EnumName,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[pscustomobject]$Values,
2020-12-08 12:00:26 -05:00
[switch]$PassThru
)
2020-12-08 12:00:26 -05:00
$definition = @"
public enum $EnumName
{`n$(foreach ($value in $values) {
"`t$($value.label) = $($value.value),`n"
})
}
"@
if (-not ([System.Management.Automation.PSTypeName]"$EnumName").Type) {
#Write-Host $definition -ForegroundColor Green
Add-Type -TypeDefinition $definition -PassThru:$PassThru
} else {
Write-Warning "EnumType $EnumName already exists."
}
}
#endregion
#region File Get-ModelDefinition.ps1
function Get-ModelDefinition {
[CmdletBinding(DefaultParameterSetName = 'ByName')]
param
(
[Parameter(ParameterSetName = 'ByName',
Mandatory = $true)]
[string]$ModelName,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByPath',
Mandatory = $true)]
[string]$URIPath,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByPath')]
[string]$Method = "post"
)
2020-12-08 12:00:26 -05:00
switch ($PsCmdlet.ParameterSetName) {
'ByName' {
$script:NetboxConfig.APIDefinition.definitions.$ModelName
break
}
2020-12-08 12:00:26 -05:00
'ByPath' {
switch ($Method) {
"get" {
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
"post" {
if (-not $URIPath.StartsWith('/')) {
$URIPath = "/$URIPath"
}
2020-12-08 12:00:26 -05:00
if (-not $URIPath.EndsWith('/')) {
$URIPath = "$URIPath/"
}
2020-12-08 12:00:26 -05:00
$ModelName = $script:NetboxConfig.APIDefinition.paths.$URIPath.post.parameters.schema.'$ref'.split('/')[-1]
$script:NetboxConfig.APIDefinition.definitions.$ModelName
break
}
}
2020-12-08 12:00:26 -05:00
break
}
}
2020-12-08 12:00:26 -05:00
}
#endregion
#region File Get-NetboxAPIDefinition.ps1
function Get-NetboxAPIDefinition {
[CmdletBinding()]
param ()
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
#$URI = "https://netbox.neonet.org/api/docs/?format=openapi"
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('docs'))
2021-07-22 11:53:58 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{'format' = 'openapi' }
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
2021-07-22 11:53:58 -04:00
InvokeNetboxRequest -URI $URI
2020-12-08 12:00:26 -05:00
}
#endregion
#region File GetNetboxAPIErrorBody.ps1
function GetNetboxAPIErrorBody {
param
(
[Parameter(Mandatory = $true)]
[System.Net.HttpWebResponse]$Response
)
2020-12-08 12:00:26 -05:00
# This takes the $Response stream and turns it into a useable object... generally a string.
# If the body is JSON, you should be able to use ConvertFrom-Json
2020-12-08 12:00:26 -05:00
$reader = New-Object System.IO.StreamReader($Response.GetResponseStream())
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$reader.ReadToEnd()
}
#endregion
#region File Get-NetboxCircuit.ps1
function Get-NetboxCircuit {
2021-07-23 16:19:03 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
Gets one or more circuits
2020-12-08 12:00:26 -05:00
.DESCRIPTION
A detailed description of the Get-NetboxCircuit function.
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Database ID of circuit. This will query for exactly the IDs provided
2020-12-08 12:00:26 -05:00
.PARAMETER CID
Circuit ID
2020-12-08 12:00:26 -05:00
.PARAMETER InstallDate
Date of installation
2020-12-08 12:00:26 -05:00
.PARAMETER CommitRate
Committed rate in Kbps
2020-12-08 12:00:26 -05:00
.PARAMETER Query
A raw search query... As if you were searching the web site
2020-12-08 12:00:26 -05:00
.PARAMETER Provider
The name or ID of the provider. Provide either [string] or [int]. String will search provider names, integer will search database IDs
2020-12-08 12:00:26 -05:00
.PARAMETER Type
Type of circuit. Provide either [string] or [int]. String will search provider type names, integer will search database IDs
2020-12-08 12:00:26 -05:00
.PARAMETER Site
Location/site of circuit. Provide either [string] or [int]. String will search site names, integer will search database IDs
2020-12-08 12:00:26 -05:00
.PARAMETER Tenant
Tenant assigned to circuit. Provide either [string] or [int]. String will search tenant names, integer will search database IDs
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
A description of the Limit parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Offset
A description of the Offset parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER ID__IN
Multiple unique DB IDs to retrieve
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Get-NetboxCircuit
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$CID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[datetime]$InstallDate,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$CommitRate,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Provider,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Type,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Site,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
process {
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits', $i))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
2021-07-23 16:19:03 -04:00
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
}
}
#endregion
#region File Get-NetboxCircuitProvider.ps1
function Get-NetboxCircuitProvider {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById',
Mandatory = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query',
Mandatory = $false)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$ASN,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Account,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers', $i))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'providers'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}
#endregion
#region File Get-NetboxCircuitTermination.ps1
function Get-NetboxCircuitTermination {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById',
ValueFromPipelineByPropertyName = $true)]
[uint32[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Circuit_ID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Term_Side,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Port_Speed,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Site_ID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Site,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$XConnect_ID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
process {
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations', $i))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-terminations'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}
}
#endregion
#region File Get-NetboxCircuitType.ps1
function Get-NetboxCircuitType {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($i in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit_types', $i))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuit-types'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}
#endregion
#region File GetNetboxConfigVariable.ps1
function GetNetboxConfigVariable {
return $script:NetboxConfig
}
#endregion
2023-02-16 09:49:13 -05:00
#region File Get-NetboxContact.ps1
function Get-NetboxContact {
<#
.SYNOPSIS
Get a contact from Netbox
.DESCRIPTION
Obtain a contact or contacts from Netbox by ID or query
.PARAMETER Name
The specific name of the Contact. Must match exactly as is defined in Netbox
.PARAMETER Id
The database ID of the Contact
.PARAMETER Query
A standard search query that will match one or more Contacts.
.PARAMETER Email
Email address of the contact
.PARAMETER Title
Title of the contact
.PARAMETER Phone
Telephone number of the contact
.PARAMETER Address
Physical address of the contact
.PARAMETER Group
The specific group as defined in Netbox.
.PARAMETER GroupID
The database ID of the group in Netbox
.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-NetboxContact
.NOTES
Additional information about the function.
#>
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Name,
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[string]$Email,
[Parameter(ParameterSetName = 'Query')]
[string]$Title,
[Parameter(ParameterSetName = 'Query')]
[string]$Phone,
[Parameter(ParameterSetName = 'Query')]
[string]$Address,
[Parameter(ParameterSetName = 'Query')]
[string]$Group,
[Parameter(ParameterSetName = 'Query')]
[uint16]$GroupID,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($Contact_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts', $Contact_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', 'contacts'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}
#endregion
#region File Get-NetboxContactAssignment.ps1
function Get-NetboxContactAssignment {
<#
.SYNOPSIS
Get a contact Assignment from Netbox
.DESCRIPTION
A detailed description of the Get-NetboxContactAssignment function.
.PARAMETER Name
The specific name of the contact Assignment. Must match exactly as is defined in Netbox
.PARAMETER Id
The database ID of the contact Assignment
.PARAMETER Content_Type_Id
A description of the Content_Type_Id parameter.
.PARAMETER Content_Type
A description of the Content_Type parameter.
.PARAMETER Object_Id
A description of the Object_Id parameter.
.PARAMETER Contact_Id
A description of the Contact_Id parameter.
.PARAMETER Role_Id
A description of the Role_Id parameter.
.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-NetboxContactAssignment
.NOTES
Additional information about the function.
#>
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Name,
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Content_Type_Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Content_Type,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Object_Id,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Contact_Id,
[Parameter(ParameterSetName = 'Query')]
[uint32]$Role_Id,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($ContactAssignment_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-assignments', $ContactAssignment_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', 'contact-assignments'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}
#endregion
#region File Get-NetboxContactRole.ps1
function Get-NetboxContactRole {
<#
.SYNOPSIS
Get a contact role from Netbox
.DESCRIPTION
A detailed description of the Get-NetboxContactRole function.
.PARAMETER Name
The specific name of the contact role. Must match exactly as is defined in Netbox
.PARAMETER Id
The database ID of the contact role
.PARAMETER Query
A standard search query that will match one or more contact roles.
.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-NetboxContactRole
.NOTES
Additional information about the function.
#>
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Name,
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
[Parameter(ParameterSetName = 'Query')]
[string]$Description,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($ContactRole_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contact-roles', $ContactRole_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', 'contact-roles'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}
#endregion
#region File Get-NetboxContentType.ps1
function Get-NetboxContentType {
<#
.SYNOPSIS
Get a content type definition from Netbox
.DESCRIPTION
A detailed description of the Get-NetboxContentType function.
.PARAMETER Model
A description of the Model parameter.
.PARAMETER Id
The database ID of the contact role
.PARAMETER App_Label
A description of the App_Label parameter.
.PARAMETER Query
A standard search query that will match one or more contact roles.
.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-NetboxContentType
.NOTES
Additional information about the function.
#>
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Model,
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
[Parameter(ParameterSetName = 'Query')]
[string]$App_Label,
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
[switch]$Raw
)
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($ContentType_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('extras', 'content-types', $ContentType_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(@('extras', 'content-types'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
break
}
}
}
#endregion
2020-12-08 12:00:26 -05:00
#region File Get-NetboxCredential.ps1
function Get-NetboxCredential {
[CmdletBinding()]
[OutputType([pscredential])]
param ()
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
if (-not $script:NetboxConfig.Credential) {
throw "Netbox Credentials not set! You may set with Set-NetboxCredential"
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$script:NetboxConfig.Credential
}
#endregion
#region File Get-NetboxDCIMDevice.ps1
function Get-NetboxDCIMDevice {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Query,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[uint16]$Manufacturer_Id,
2020-12-08 12:00:26 -05:00
[string]$Manufacturer,
2020-12-08 12:00:26 -05:00
[uint16]$Device_Type_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Role_Id,
2020-12-08 12:00:26 -05:00
[string]$Role,
2020-12-08 12:00:26 -05:00
[uint16]$Tenant_Id,
2020-12-08 12:00:26 -05:00
[string]$Tenant,
2020-12-08 12:00:26 -05:00
[uint16]$Platform_Id,
2020-12-08 12:00:26 -05:00
[string]$Platform,
2020-12-08 12:00:26 -05:00
[string]$Asset_Tag,
2020-12-08 12:00:26 -05:00
[uint16]$Site_Id,
2020-12-08 12:00:26 -05:00
[string]$Site,
2020-12-08 12:00:26 -05:00
[uint16]$Rack_Group_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Rack_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Model,
2020-12-08 12:00:26 -05:00
[object]$Status,
2020-12-08 12:00:26 -05:00
[bool]$Is_Full_Depth,
2020-12-08 12:00:26 -05:00
[bool]$Is_Console_Server,
2020-12-08 12:00:26 -05:00
[bool]$Is_PDU,
2020-12-08 12:00:26 -05:00
[bool]$Is_Network_Device,
2020-12-08 12:00:26 -05:00
[string]$MAC_Address,
2020-12-08 12:00:26 -05:00
[bool]$Has_Primary_IP,
2020-12-08 12:00:26 -05:00
[uint16]$Virtual_Chassis_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Position,
2020-12-08 12:00:26 -05:00
[string]$Serial,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
#endregion Parameters
2021-07-23 16:19:03 -04:00
process {
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
}
2021-07-23 16:19:03 -04:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
#endregion
#region File Get-NetboxDCIMDeviceRole.ps1
function Get-NetboxDCIMDeviceRole {
[CmdletBinding()]
param
(
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[string]$Slug,
2020-12-08 12:00:26 -05:00
[string]$Color,
2020-12-08 12:00:26 -05:00
[bool]$VM_Role,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($DRId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles', $DRId))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}
#endregion
#region File Get-NetboxDCIMDeviceType.ps1
function Get-NetboxDCIMDeviceType {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Query,
2020-12-08 12:00:26 -05:00
[string]$Slug,
2020-12-08 12:00:26 -05:00
[string]$Manufacturer,
2020-12-08 12:00:26 -05:00
[uint16]$Manufacturer_Id,
2020-12-08 12:00:26 -05:00
[string]$Model,
2020-12-08 12:00:26 -05:00
[string]$Part_Number,
2020-12-08 12:00:26 -05:00
[uint16]$U_Height,
2020-12-08 12:00:26 -05:00
[bool]$Is_Full_Depth,
2020-12-08 12:00:26 -05:00
[bool]$Is_Console_Server,
2020-12-08 12:00:26 -05:00
[bool]$Is_PDU,
2020-12-08 12:00:26 -05:00
[bool]$Is_Network_Device,
2020-12-08 12:00:26 -05:00
[uint16]$Subdevice_Role,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
#endregion Parameters
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
#endregion
#region File Get-NetboxDCIMInterface.ps1
function Get-NetboxDCIMInterface {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[Parameter(ValueFromPipelineByPropertyName = $true)]
[uint16]$Id,
2020-12-08 12:00:26 -05:00
[uint16]$Name,
2020-12-08 12:00:26 -05:00
[object]$Form_Factor,
2020-12-08 12:00:26 -05:00
[bool]$Enabled,
2020-12-08 12:00:26 -05:00
[uint16]$MTU,
2020-12-08 12:00:26 -05:00
[bool]$MGMT_Only,
2020-12-08 12:00:26 -05:00
[string]$Device,
2020-12-08 12:00:26 -05:00
[uint16]$Device_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Type,
2020-12-08 12:00:26 -05:00
[uint16]$LAG_Id,
2020-12-08 12:00:26 -05:00
[string]$MAC_Address,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
process {
if ($null -ne $Form_Factor) {
$PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
}
2021-07-23 16:19:03 -04:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces'))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
#endregion
#region File Get-NetboxDCIMInterfaceConnection.ps1
function Get-NetboxDCIMInterfaceConnection {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[uint16]$Id,
2020-12-08 12:00:26 -05:00
[object]$Connection_Status,
2020-12-08 12:00:26 -05:00
[uint16]$Site,
2020-12-08 12:00:26 -05:00
[uint16]$Device,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
if ($null -ne $Connection_Status) {
$PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
}
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
#endregion
#region File Get-NetboxDCIMPlatform.ps1
function Get-NetboxDCIMPlatform {
[CmdletBinding()]
[OutputType([pscustomobject])]
param
(
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[string]$Slug,
2020-12-08 12:00:26 -05:00
[uint16]$Manufacturer_Id,
2020-12-08 12:00:26 -05:00
[string]$Manufacturer,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($PlatformID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $PlatformID))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
}
}
#endregion
#region File Get-NetboxDCIMSite.ps1
function Get-NetboxDCIMSite {
2022-12-06 13:35:56 -05:00
[CmdletBinding(DefaultParameterSetName = 'Query')]
2020-12-08 12:00:26 -05:00
[OutputType([pscustomobject])]
param
(
[Parameter(ParameterSetName = 'ByID', ValueFromPipelineByPropertyName = $true)]
[uint32]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Facility,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$ASN,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[decimal]$Latitude,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[decimal]$Longitude,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Contact_Name,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Contact_Phone,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Contact_Email,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Group_ID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant_Group,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_ID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Status,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Region_ID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Region,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
process {
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($Site_ID in $ID) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $Site_Id))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName "Id"
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
2021-07-23 16:19:03 -04:00
default {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites'))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $URI -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
}
}
#endregion
#region File Get-NetboxHostname.ps1
function Get-NetboxHostname {
[CmdletBinding()]
param ()
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
Write-Verbose "Getting Netbox hostname"
if ($null -eq $script:NetboxConfig.Hostname) {
throw "Netbox Hostname is not set! You may set it with Set-NetboxHostname -Hostname 'hostname.domain.tld'"
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$script:NetboxConfig.Hostname
}
#endregion
2021-03-31 10:24:08 -04:00
#region File Get-NetboxHostPort.ps1
function Get-NetboxHostPort {
[CmdletBinding()]
param ()
2021-03-31 10:24:08 -04:00
Write-Verbose "Getting Netbox host port"
if ($null -eq $script:NetboxConfig.HostPort) {
throw "Netbox host port is not set! You may set it with Set-NetboxHostPort -Port 'https'"
}
2021-03-31 10:24:08 -04:00
$script:NetboxConfig.HostPort
}
#endregion
#region File Get-NetboxHostScheme.ps1
function Get-NetboxHostScheme {
[CmdletBinding()]
param ()
2021-03-31 10:24:08 -04:00
Write-Verbose "Getting Netbox host scheme"
if ($null -eq $script:NetboxConfig.Hostscheme) {
throw "Netbox host sceme is not set! You may set it with Set-NetboxHostScheme -Scheme 'https'"
}
2021-03-31 10:24:08 -04:00
$script:NetboxConfig.HostScheme
}
#endregion
2021-07-22 11:53:58 -04:00
#region File Get-NetboxInvokeParams.ps1
function Get-NetboxInvokeParams {
[CmdletBinding()]
param ()
Write-Verbose "Getting Netbox InvokeParams"
if ($null -eq $script:NetboxConfig.InvokeParams) {
throw "Netbox Invoke Params is not set! You may set it with Set-NetboxInvokeParams -InvokeParams ..."
}
$script:NetboxConfig.InvokeParams
}
#endregion
2020-12-08 12:00:26 -05:00
#region File Get-NetboxIPAMAddress.ps1
function Get-NetboxIPAMAddress {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
2021-03-30 11:00:53 -04:00
Position = 0)]
2020-12-08 12:00:26 -05:00
[string]$Address,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Family,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
2022-12-06 13:35:56 -05:00
[string]$Parent,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[byte]$Mask_Length,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$VRF,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$VRF_Id,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Id,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Device,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Device_ID,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Virtual_Machine,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Virtual_Machine_Id,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Interface_Id,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Status,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Role,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($IP_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IP_ID))
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
break
}
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
break
}
}
}
#endregion
#region File Get-NetboxIPAMAggregate.ps1
function Get-NetboxIPAMAggregate {
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByID')]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Prefix,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Family,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$RIR_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$RIR,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[datetime]$Date_Added,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
# if ($null -ne $Family) {
# $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -AggregateFamily
# }
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($IP_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates', $IP_ID))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
break
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'aggregates'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
2020-12-08 12:00:26 -05:00
break
}
}
}
#endregion
#region File Get-NetboxIPAMAvailableIP.ps1
function Get-NetboxIPAMAvailableIP {
2021-03-30 11:00:53 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
A convenience method for returning available IP addresses within a prefix
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.DESCRIPTION
By default, the number of IPs returned will be equivalent to PAGINATE_COUNT. An arbitrary limit
(up to MAX_PAGE_SIZE, if set) may be passed, however results will not be paginated
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Prefix_ID
A description of the Prefix_ID parameter.
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
A description of the Limit parameter.
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER NumberOfIPs
A description of the NumberOfIPs parameter.
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.EXAMPLE
2021-07-23 10:26:14 -04:00
Get-NetboxIPAMAvailableIP -Prefix_ID (Get-NetboxIPAMPrefix -Prefix 192.0.2.0/24).id
Get (Next) Available IP on the Prefix 192.0.2.0/24
.EXAMPLE
Get-NetboxIPAMAvailableIP -Prefix_ID 2 -NumberOfIPs 3
Get 3 (Next) Available IP on the Prefix 192.0.2.0/24
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,
2021-03-30 11:00:53 -04:00
ValueFromPipelineByPropertyName = $true)]
2020-12-08 12:00:26 -05:00
[Alias('Id')]
2021-03-30 11:00:53 -04:00
[int]$Prefix_ID,
2020-12-08 12:00:26 -05:00
[Alias('NumberOfIPs')]
2021-03-30 11:00:53 -04:00
[int]$Limit,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-03-30 11:00:53 -04:00
process {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID, 'available-ips'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'prefix_id'
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
#endregion
#region File Get-NetboxIPAMPrefix.ps1
function Get-NetboxIPAMPrefix {
<#
.SYNOPSIS
A brief description of the Get-NetboxIPAMPrefix function.
2020-12-08 12:00:26 -05:00
.DESCRIPTION
A detailed description of the Get-NetboxIPAMPrefix function.
2020-12-08 12:00:26 -05:00
.PARAMETER Query
A description of the Query parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Id
A description of the Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
A description of the Limit parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Offset
A description of the Offset parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Family
A description of the Family parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Is_Pool
A description of the Is_Pool parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Within
Should be a CIDR notation prefix such as '10.0.0.0/16'
2020-12-08 12:00:26 -05:00
.PARAMETER Within_Include
Should be a CIDR notation prefix such as '10.0.0.0/16'
2020-12-08 12:00:26 -05:00
.PARAMETER Contains
A description of the Contains parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Mask_Length
CIDR mask length value
2020-12-08 12:00:26 -05:00
.PARAMETER VRF
A description of the VRF parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER VRF_Id
A description of the VRF_Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Tenant
A description of the Tenant parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Tenant_Id
A description of the Tenant_Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Site
A description of the Site parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Site_Id
A description of the Site_Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Vlan_VId
A description of the Vlan_VId parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Vlan_Id
A description of the Vlan_Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Status
A description of the Status parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Role
A description of the Role parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Role_Id
A description of the Role_Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Get-NetboxIPAMPrefix
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Prefix,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Family,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[boolean]$Is_Pool,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Within,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Within_Include,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Contains,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[ValidateRange(0, 127)]
[byte]$Mask_Length,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$VRF,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$VRF_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Site,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Site_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Vlan_VId,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Vlan_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Status,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Role,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Role_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
# if ($null -ne $Family) {
# $PSBoundParameters.Family = ValidateIPAMChoice -ProvidedValue $Family -PrefixFamily
# }
#
2020-12-08 12:00:26 -05:00
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
# }
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($Prefix_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $Prefix_ID))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
2020-12-08 12:00:26 -05:00
break
}
}
}
#endregion
#region File Get-NetboxIPAMRole.ps1
function Get-NetboxIPAMRole {
<#
.SYNOPSIS
Get IPAM Prefix/VLAN roles
2020-12-08 12:00:26 -05:00
.DESCRIPTION
A role indicates the function of a prefix or VLAN. For example, you might define Data, Voice, and Security roles. Generally, a prefix will be assigned the same functional role as the VLAN to which it is assigned (if any).
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Unique ID
2020-12-08 12:00:26 -05:00
.PARAMETER Query
Search query
2020-12-08 12:00:26 -05:00
.PARAMETER Name
Role name
2020-12-08 12:00:26 -05:00
.PARAMETER Slug
Role URL slug
2020-12-08 12:00:26 -05:00
.PARAMETER Brief
Brief format
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
Result limit
2020-12-08 12:00:26 -05:00
.PARAMETER Offset
Result offset
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Get-NetboxIPAMRole
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[switch]$Brief,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($Role_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles', $Role_ID))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'roles'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
2020-12-08 12:00:26 -05:00
break
}
}
}
#endregion
#region File Get-NetboxIPAMVLAN.ps1
function Get-NetboxIPAMVLAN {
[CmdletBinding()]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[ValidateRange(1, 4096)]
[uint16]$VID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Tenant,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Tenant_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$TenantGroup,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$TenantGroup_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[object]$Status,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Region,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Site,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Site_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Group,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Group_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Role,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint32]$Role_Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
# }
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($VLAN_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans', $VLAN_ID))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
2020-12-08 12:00:26 -05:00
break
}
}
}
#endregion
#region File Get-NetboxTenant.ps1
function Get-NetboxTenant {
<#
.SYNOPSIS
Get a tenent from Netbox
2020-12-08 12:00:26 -05:00
.DESCRIPTION
A detailed description of the Get-NetboxTenant function.
2020-12-08 12:00:26 -05:00
.PARAMETER Name
The specific name of the tenant. Must match exactly as is defined in Netbox
2020-12-08 12:00:26 -05:00
.PARAMETER Id
The database ID of the tenant
2020-12-08 12:00:26 -05:00
.PARAMETER Query
A standard search query that will match one or more tenants.
2020-12-08 12:00:26 -05:00
.PARAMETER Slug
The specific slug of the tenant. Must match exactly as is defined in Netbox
2020-12-08 12:00:26 -05:00
.PARAMETER Group
The specific group as defined in Netbox.
2020-12-08 12:00:26 -05:00
.PARAMETER GroupID
The database ID of the group in Netbox
2020-12-08 12:00:26 -05:00
.PARAMETER CustomFields
Hashtable in the format @{"field_name" = "value"} to search
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
Limit the number of results to this number
2020-12-08 12:00:26 -05:00
.PARAMETER Offset
Start the search at this index in results
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
Return the unparsed data from the HTTP request
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Get-NetboxTenant
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding(DefaultParameterSetName = 'Query')]
param
(
[Parameter(ParameterSetName = 'Query',
Position = 0)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'ByID')]
[uint32[]]$Id,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Slug,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[string]$Group,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$GroupID,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[hashtable]$CustomFields,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'Query')]
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($Tenant_ID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants', $Tenant_ID))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
break
}
2020-12-08 12:00:26 -05:00
default {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
2020-12-08 12:00:26 -05:00
break
}
}
}
#endregion
2021-07-22 11:53:58 -04:00
#region File Get-NetboxTimeout.ps1
function Get-NetboxTimeout {
[CmdletBinding()]
[OutputType([uint16])]
param ()
Write-Verbose "Getting Netbox Timeout"
if ($null -eq $script:NetboxConfig.Timeout) {
throw "Netbox Timeout is not set! You may set it with Set-NetboxTimeout -TimeoutSeconds [uint16]"
}
$script:NetboxConfig.Timeout
}
#endregion
#region File Get-NetboxVersion.ps1
function Get-NetboxVersion {
[CmdletBinding()]
param ()
$Segments = [System.Collections.ArrayList]::new(@('status'))
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary @{
'format' = 'json'
}
$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters -SkipConnectedCheck
InvokeNetboxRequest -URI $URI
}
#endregion
2020-12-08 12:00:26 -05:00
#region File Get-NetboxVirtualizationCluster.ps1
function Get-NetboxVirtualizationCluster {
<#
.SYNOPSIS
Obtains virtualization clusters from Netbox.
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Obtains one or more virtualization clusters based on provided filters.
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
Number of results to return per page
2020-12-08 12:00:26 -05:00
.PARAMETER Offset
The initial index from which to return the results
2020-12-08 12:00:26 -05:00
.PARAMETER Query
A general query used to search for a cluster
2020-12-08 12:00:26 -05:00
.PARAMETER Name
Name of the cluster
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Database ID(s) of the cluster
2020-12-08 12:00:26 -05:00
.PARAMETER Group
String value of the cluster group.
2020-12-08 12:00:26 -05:00
.PARAMETER Group_Id
Database ID of the cluster group.
2020-12-08 12:00:26 -05:00
.PARAMETER Type
String value of the Cluster type.
2020-12-08 12:00:26 -05:00
.PARAMETER Type_Id
Database ID of the cluster type.
2020-12-08 12:00:26 -05:00
.PARAMETER Site
String value of the site.
2020-12-08 12:00:26 -05:00
.PARAMETER Site_Id
Database ID of the site.
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Get-NetboxVirtualizationCluster
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
param
(
[string]$Name,
2020-12-08 12:00:26 -05:00
[Alias('q')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Group,
2020-12-08 12:00:26 -05:00
[uint16]$Group_Id,
2020-12-08 12:00:26 -05:00
[string]$Type,
2020-12-08 12:00:26 -05:00
[uint16]$Type_Id,
2020-12-08 12:00:26 -05:00
[string]$Site,
2020-12-08 12:00:26 -05:00
[uint16]$Site_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'clusters'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
#endregion
#region File Get-NetboxVirtualizationClusterGroup.ps1
function Get-NetboxVirtualizationClusterGroup {
[CmdletBinding()]
param
(
[string]$Name,
2020-12-08 12:00:26 -05:00
[string]$Slug,
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[string]$Query,
2020-12-08 12:00:26 -05:00
[uint32[]]$Id,
2020-12-08 12:00:26 -05:00
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'cluster-groups'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
#endregion
#region File Get-NetboxVirtualMachine.ps1
function Get-NetboxVirtualMachine {
2021-07-23 16:19:03 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
Obtains virtual machines from Netbox.
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Obtains one or more virtual machines based on provided filters.
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
Number of results to return per page
2020-12-08 12:00:26 -05:00
.PARAMETER Offset
The initial index from which to return the results
2020-12-08 12:00:26 -05:00
.PARAMETER Query
A general query used to search for a VM
2020-12-08 12:00:26 -05:00
.PARAMETER Name
Name of the VM
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Database ID of the VM
2020-12-08 12:00:26 -05:00
.PARAMETER Status
Status of the VM
2020-12-08 12:00:26 -05:00
.PARAMETER Tenant
String value of tenant
2020-12-08 12:00:26 -05:00
.PARAMETER Tenant_ID
Database ID of the tenant.
2020-12-08 12:00:26 -05:00
.PARAMETER Platform
String value of the platform
2020-12-08 12:00:26 -05:00
.PARAMETER Platform_ID
Database ID of the platform
2020-12-08 12:00:26 -05:00
.PARAMETER Cluster_Group
String value of the cluster group.
2020-12-08 12:00:26 -05:00
.PARAMETER Cluster_Group_Id
Database ID of the cluster group.
2020-12-08 12:00:26 -05:00
.PARAMETER Cluster_Type
String value of the Cluster type.
2020-12-08 12:00:26 -05:00
.PARAMETER Cluster_Type_Id
Database ID of the cluster type.
2020-12-08 12:00:26 -05:00
.PARAMETER Cluster_Id
Database ID of the cluster.
2020-12-08 12:00:26 -05:00
.PARAMETER Site
String value of the site.
2020-12-08 12:00:26 -05:00
.PARAMETER Site_Id
Database ID of the site.
2020-12-08 12:00:26 -05:00
.PARAMETER Role
String value of the role.
2020-12-08 12:00:26 -05:00
.PARAMETER Role_Id
Database ID of the role.
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER TenantID
Database ID of tenant
2020-12-08 12:00:26 -05:00
.PARAMETER PlatformID
Database ID of the platform
2020-12-08 12:00:26 -05:00
.PARAMETER id__in
Database IDs of VMs
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Get-NetboxVirtualMachine
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
param
(
[Alias('q')]
[string]$Query,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[object]$Status,
2020-12-08 12:00:26 -05:00
[string]$Tenant,
2020-12-08 12:00:26 -05:00
[uint16]$Tenant_ID,
2020-12-08 12:00:26 -05:00
[string]$Platform,
2020-12-08 12:00:26 -05:00
[uint16]$Platform_ID,
2020-12-08 12:00:26 -05:00
[string]$Cluster_Group,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster_Group_Id,
2020-12-08 12:00:26 -05:00
[string]$Cluster_Type,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster_Type_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster_Id,
2020-12-08 12:00:26 -05:00
[string]$Site,
2020-12-08 12:00:26 -05:00
[uint16]$Site_Id,
2020-12-08 12:00:26 -05:00
[string]$Role,
2020-12-08 12:00:26 -05:00
[uint16]$Role_Id,
2020-12-08 12:00:26 -05:00
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
process {
if ($null -ne $Status) {
$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
}
2021-07-23 16:19:03 -04:00
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2021-07-23 16:19:03 -04:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
#endregion
#region File Get-NetboxVirtualMachineInterface.ps1
function Get-NetboxVirtualMachineInterface {
2021-07-23 16:19:03 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
Gets VM interfaces
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Obtains the interface objects for one or more VMs
2020-12-08 12:00:26 -05:00
.PARAMETER Limit
Number of results to return per page.
2020-12-08 12:00:26 -05:00
.PARAMETER Offset
The initial index from which to return the results.
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Database ID of the interface
2020-12-08 12:00:26 -05:00
.PARAMETER Name
Name of the interface
2020-12-08 12:00:26 -05:00
.PARAMETER Enabled
True/False if the interface is enabled
2020-12-08 12:00:26 -05:00
.PARAMETER MTU
Maximum Transmission Unit size. Generally 1500 or 9000
2020-12-08 12:00:26 -05:00
.PARAMETER Virtual_Machine_Id
ID of the virtual machine to which the interface(s) are assigned.
2020-12-08 12:00:26 -05:00
.PARAMETER Virtual_Machine
Name of the virtual machine to get interfaces
2020-12-08 12:00:26 -05:00
.PARAMETER MAC_Address
MAC address assigned to the interface
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
A description of the Raw parameter.
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Get-NetboxVirtualMachineInterface
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
param
(
[Parameter(ValueFromPipeline = $true)]
[uint16]$Id,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[string]$Query,
2020-12-08 12:00:26 -05:00
[boolean]$Enabled,
2020-12-08 12:00:26 -05:00
[uint16]$MTU,
2020-12-08 12:00:26 -05:00
[uint16]$Virtual_Machine_Id,
2020-12-08 12:00:26 -05:00
[string]$Virtual_Machine,
2020-12-08 12:00:26 -05:00
[string]$MAC_Address,
2020-12-08 12:00:26 -05:00
[uint16]$Limit,
2020-12-08 12:00:26 -05:00
[uint16]$Offset,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces'))
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2021-07-23 16:19:03 -04:00
$uri = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $uri -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
2023-02-16 09:49:13 -05:00
#endregion
#region File Initialize-NetboxContentTypeEnum.ps1
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2022 v5.8.212
Created on: 2023-02-15 16:47
Created by: Claussen
Organization: NEOnet
Filename: Initialize-NetboxContentTypeEnum.ps1
===========================================================================
.DESCRIPTION
A description of the file.
#>
2020-12-08 12:00:26 -05:00
#endregion
#region File InvokeNetboxRequest.ps1
function InvokeNetboxRequest {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[System.UriBuilder]$URI,
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
[Hashtable]$Headers = @{
},
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
[pscustomobject]$Body = $null,
2021-07-22 11:53:58 -04:00
[ValidateRange(1, 65535)]
[uint16]$Timeout = (Get-NetboxTimeout),
2020-12-08 12:00:26 -05:00
[ValidateSet('GET', 'PATCH', 'PUT', 'POST', 'DELETE', 'OPTIONS', IgnoreCase = $true)]
[string]$Method = 'GET',
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$creds = Get-NetboxCredential
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$Headers.Authorization = "Token {0}" -f $creds.GetNetworkCredential().Password
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$splat = @{
2021-07-22 11:53:58 -04:00
'Method' = $Method
'Uri' = $URI.Uri.AbsoluteUri # This property auto generates the scheme, hostname, path, and query
'Headers' = $Headers
'TimeoutSec' = $Timeout
2020-12-08 12:00:26 -05:00
'ContentType' = 'application/json'
'ErrorAction' = 'Stop'
2021-07-22 11:53:58 -04:00
'Verbose' = $VerbosePreference
2020-12-08 12:00:26 -05:00
}
2021-07-22 11:53:58 -04:00
$splat += Get-NetboxInvokeParams
2020-12-08 12:00:26 -05:00
if ($Body) {
Write-Verbose "BODY: $($Body | ConvertTo-Json -Compress)"
$null = $splat.Add('Body', ($Body | ConvertTo-Json -Compress))
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$result = Invoke-RestMethod @splat
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
#region TODO: Handle errors a little more gracefully...
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
<#
try {
Write-Verbose "Sending request..."
$result = Invoke-RestMethod @splat
Write-Verbose $result
} catch {
Write-Verbose "Caught exception"
if ($_.Exception.psobject.properties.Name.contains('Response')) {
Write-Verbose "Exception contains a response property"
if ($Raw) {
Write-Verbose "RAW provided...throwing raw exception"
throw $_
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
Write-Verbose "Converting response to object"
$myError = GetNetboxAPIErrorBody -Response $_.Exception.Response | ConvertFrom-Json
} else {
Write-Verbose "No response property found"
$myError = $_
}
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
Write-Verbose "MyError is $($myError.GetType().FullName)"
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
if ($myError -is [Exception]) {
throw $_
} elseif ($myError -is [pscustomobject]) {
throw $myError.detail
2021-07-22 11:53:58 -04:00
}
2020-12-08 12:00:26 -05:00
#>
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
#endregion TODO: Handle errors a little more gracefully...
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
# If the user wants the raw value from the API... otherwise return only the actual result
if ($Raw) {
Write-Verbose "Returning raw result by choice"
return $result
} else {
if ($result.psobject.Properties.Name.Contains('results')) {
Write-Verbose "Found Results property on data, returning results directly"
return $result.Results
} else {
Write-Verbose "Did NOT find results property on data, returning raw result"
return $result
}
}
}
#endregion
#region File New-NetboxCircuit.ps1
function New-NetboxCircuit {
[CmdletBinding(ConfirmImpact = 'Low',
2021-07-23 16:19:03 -04:00
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
2021-07-23 16:19:03 -04:00
ValueFromPipelineByPropertyName = $true)]
2020-12-08 12:00:26 -05:00
[string]$CID,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[uint32]$Provider,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[uint32]$Type,
2020-12-08 12:00:26 -05:00
#[ValidateSet('Active', 'Planned', 'Provisioning', 'Offline', 'Deprovisioning', 'Decommissioned ')]
[uint16]$Status = 'Active',
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[uint32]$Tenant,
2020-12-08 12:00:26 -05:00
[string]$Termination_A,
2020-12-08 12:00:26 -05:00
[datetime]$Install_Date,
2020-12-08 12:00:26 -05:00
[string]$Termination_Z,
2020-12-08 12:00:26 -05:00
[ValidateRange(0, 2147483647)]
[uint32]$Commit_Rate,
2020-12-08 12:00:26 -05:00
[string]$Comments,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2020-12-08 12:00:26 -05:00
[switch]$Force,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
process {
$Segments = [System.Collections.ArrayList]::new(@('circuits', 'circuits'))
$Method = 'POST'
2021-07-23 16:19:03 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-07-23 16:19:03 -04:00
if ($Force -or $PSCmdlet.ShouldProcess($CID, 'Create new circuit')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
}
2023-02-16 09:49:13 -05:00
#endregion
#region File New-NetboxContact.ps1
function New-NetboxContact {
<#
.SYNOPSIS
Create a new contact in Netbox
.DESCRIPTION
Creates a new contact object in Netbox which can be linked to other objects
.PARAMETER Name
The contacts full name, e.g "Leroy Jenkins"
.PARAMETER Email
Email address of the contact
.PARAMETER Title
Job title or other title related to the contact
.PARAMETER Phone
Telephone number
.PARAMETER Address
Physical address, usually mailing address
.PARAMETER Description
Short description of the contact
.PARAMETER Comments
Detailed comments. Markdown supported.
.PARAMETER Link
URI related to the contact
.PARAMETER Custom_Fields
A description of the Custom_Fields parameter.
.PARAMETER Raw
A description of the Raw parameter.
.EXAMPLE
PS C:\> New-NetboxContact -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com'
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateLength(1, 100)]
[string]$Name,
[Parameter(Mandatory = $true)]
[ValidateLength(0, 254)]
[string]$Email,
[ValidateLength(0, 100)]
[string]$Title,
[ValidateLength(0, 50)]
[string]$Phone,
[ValidateLength(0, 200)]
[string]$Address,
[ValidateLength(0, 200)]
[string]$Description,
[string]$Comments,
[ValidateLength(0, 200)]
[string]$Link,
[hashtable]$Custom_Fields,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts'))
$Method = 'POST'
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}
#endregion
#region File New-NetboxContactRole.ps1
function New-NetboxContactRole {
<#
.SYNOPSIS
Create a new contact role in Netbox
.DESCRIPTION
Creates a new contact role object in Netbox
.PARAMETER Name
The contact role name, e.g "Network Support"
.PARAMETER Slug
The unique URL for the role. Can only contain hypens, A-Z, a-z, 0-9, and underscores
.PARAMETER Description
Short description of the contact role
.PARAMETER Custom_Fields
A description of the Custom_Fields parameter.
.PARAMETER Raw
Return the unparsed data from the HTTP request
.EXAMPLE
PS C:\> New-NetboxContact -Name 'Leroy Jenkins' -Email 'leroy.jenkins@example.com'
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateLength(1, 100)]
[string]$Name,
[Parameter(Mandatory = $true)]
[ValidateLength(1, 100)]
[ValidatePattern('^[-a-zA-Z0-9_]+$')]
[string]$Slug,
[ValidateLength(0, 200)]
[string]$Description,
[hashtable]$Custom_Fields,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'contacts'))
$Method = 'POST'
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new contact')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}
2020-12-08 12:00:26 -05:00
#endregion
#region File New-NetboxDCIMDevice.ps1
function New-NetboxDCIMDevice {
2021-07-23 16:19:03 -04:00
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([pscustomobject])]
#region Parameters
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[object]$Device_Role,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[object]$Device_Type,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[uint16]$Site,
2020-12-08 12:00:26 -05:00
[object]$Status = 'Active',
2020-12-08 12:00:26 -05:00
[uint16]$Platform,
2020-12-08 12:00:26 -05:00
[uint16]$Tenant,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster,
2020-12-08 12:00:26 -05:00
[uint16]$Rack,
2020-12-08 12:00:26 -05:00
[uint16]$Position,
2020-12-08 12:00:26 -05:00
[object]$Face,
2020-12-08 12:00:26 -05:00
[string]$Serial,
2020-12-08 12:00:26 -05:00
[string]$Asset_Tag,
2020-12-08 12:00:26 -05:00
[uint16]$Virtual_Chassis,
2020-12-08 12:00:26 -05:00
[uint16]$VC_Priority,
2020-12-08 12:00:26 -05:00
[uint16]$VC_Position,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP4,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP6,
2020-12-08 12:00:26 -05:00
[string]$Comments,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields
)
#endregion Parameters
2021-07-23 16:19:03 -04:00
# if ($null -ne $Device_Role) {
# # Validate device role?
# }
2021-07-23 16:19:03 -04:00
# if ($null -ne $Device_Type) {
# # Validate device type?
# }
2021-07-23 16:19:03 -04:00
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# }
2021-07-23 16:19:03 -04:00
# if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# }
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-07-23 16:19:03 -04:00
if ($PSCmdlet.ShouldProcess($Name, 'Create new Device')) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST
}
2020-12-08 12:00:26 -05:00
}
#endregion
2022-12-06 13:35:56 -05:00
#region File New-NetboxDCIMSite.ps1
2020-12-08 12:00:26 -05:00
2021-03-30 11:00:53 -04:00
<#
2021-07-23 16:19:03 -04:00
.NOTES
===========================================================================
2022-12-06 13:35:56 -05:00
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2020 v5.7.181
Created on: 2020-10-02 15:52
2021-07-23 16:19:03 -04:00
Created by: Claussen
Organization: NEOnet
2022-12-06 13:35:56 -05:00
Filename: New-NetboxDCIMSite.ps1
2021-07-23 16:19:03 -04:00
===========================================================================
.DESCRIPTION
A description of the file.
2020-12-08 12:00:26 -05:00
#>
2022-12-06 13:35:56 -05:00
function New-NetboxDCIMSite {
<#
.SYNOPSIS
Create a new Site to Netbox
.DESCRIPTION
Create a new Site to Netbox
.EXAMPLE
New-NetboxDCIMSite -name MySite
Add new Site MySite on Netbox
#>
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
[string]$Slug,
[string]$Facility,
[uint32]$ASN,
[decimal]$Latitude,
[decimal]$Longitude,
[string]$Contact_Name,
[string]$Contact_Phone,
[string]$Contact_Email,
[int]$Tenant_Group,
[int]$Tenant,
[string]$Status,
[uint32]$Region,
[string]$Description,
[string]$Comments,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites'))
$Method = 'POST'
if (-not $PSBoundParameters.ContainsKey('slug')) {
$PSBoundParameters.Add('slug', $name)
}
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($name, 'Create new Site')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}
#endregion
#region File New-NetboxIPAMAddress.ps1
2020-12-08 12:00:26 -05:00
function New-NetboxIPAMAddress {
2021-03-30 11:00:53 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
Create a new IP address to Netbox
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Create a new IP address to Netbox with a status of Active by default.
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Address
IP address in CIDR notation: 192.168.1.1/24
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Status
Status of the IP. Defaults to Active
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Tenant
Tenant ID
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER VRF
VRF ID
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Role
Role such as anycast, loopback, etc... Defaults to nothing
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER NAT_Inside
ID of IP for NAT
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Interface
ID of interface to apply IP
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Description
Description of IP address
2021-03-30 11:00:53 -04:00
.PARAMETER Dns_name
DNS Name of IP address (example : netbox.example.com)
2021-07-23 16:19:03 -04:00
.PARAMETER Assigned_Object_Type
Assigned Object Type dcim.interface or virtualization.vminterface
.PARAMETER Assigned_Object_Id
Assigned Object ID
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
Return raw results from API service
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.EXAMPLE
2021-07-23 16:19:03 -04:00
New-NetboxIPAMAddress -Address 192.0.2.1/32
Add new IP Address 192.0.2.1/32 with status active
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[CmdletBinding(ConfirmImpact = 'Low',
2021-03-30 11:00:53 -04:00
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
2021-03-30 11:00:53 -04:00
ValueFromPipelineByPropertyName = $true)]
2020-12-08 12:00:26 -05:00
[string]$Address,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[object]$Status = 'Active',
2021-03-30 11:00:53 -04:00
[int]$Tenant,
[int]$VRF,
2020-12-08 12:00:26 -05:00
[object]$Role,
2021-03-30 11:00:53 -04:00
[int]$NAT_Inside,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2021-03-30 11:00:53 -04:00
[int]$Interface,
2020-12-08 12:00:26 -05:00
[string]$Description,
2021-03-30 11:00:53 -04:00
[string]$Dns_name,
2021-07-23 16:19:03 -04:00
[ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
[int]$Assigned_Object_Id,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-03-30 11:00:53 -04:00
process {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses'))
$Method = 'POST'
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-07-23 16:19:03 -04:00
if ($PSCmdlet.ShouldProcess($Address, 'Create new IP address')) {
2021-03-30 11:00:53 -04:00
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File New-NetboxIPAMPrefix.ps1
function New-NetboxIPAMPrefix {
2021-07-23 16:19:03 -04:00
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$Prefix,
2020-12-08 12:00:26 -05:00
[object]$Status = 'Active',
2020-12-08 12:00:26 -05:00
[uint16]$Tenant,
2020-12-08 12:00:26 -05:00
[object]$Role,
2020-12-08 12:00:26 -05:00
[bool]$IsPool,
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[uint16]$Site,
2020-12-08 12:00:26 -05:00
[uint16]$VRF,
2020-12-08 12:00:26 -05:00
[uint16]$VLAN,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -PrefixStatus
2020-12-08 12:00:26 -05:00
<#
# As of 2018/10/18, this does not appear to be a validated IPAM choice
if ($null -ne $Role) {
$PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -PrefixRole
}
#>
2020-12-08 12:00:26 -05:00
$segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-07-23 16:19:03 -04:00
if ($PSCmdlet.ShouldProcess($Prefix, 'Create new Prefix')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
#endregion
#region File New-NetboxIPAMVLAN.ps1
function New-NetboxIPAMVLAN {
2021-07-23 16:19:03 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
Create a new VLAN
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Create a new VLAN in Netbox with a status of Active by default.
2020-12-08 12:00:26 -05:00
.PARAMETER VID
The VLAN ID.
2020-12-08 12:00:26 -05:00
.PARAMETER Name
The name of the VLAN.
2020-12-08 12:00:26 -05:00
.PARAMETER Status
Status of the VLAN. Defaults to Active
2020-12-08 12:00:26 -05:00
.PARAMETER Tenant
Tenant ID
2020-12-08 12:00:26 -05:00
.PARAMETER Role
Role such as anycast, loopback, etc... Defaults to nothing
2020-12-08 12:00:26 -05:00
.PARAMETER Description
Description of IP address
2020-12-08 12:00:26 -05:00
.PARAMETER Custom_Fields
Custom field hash table. Will be validated by the API service
2020-12-08 12:00:26 -05:00
.PARAMETER Raw
Return raw results from API service
2020-12-08 12:00:26 -05:00
.PARAMETER Address
IP address in CIDR notation: 192.168.1.1/24
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Create-NetboxIPAMAddress
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2021-07-23 16:19:03 -04:00
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[uint16]$VID,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[object]$Status = 'Active',
2020-12-08 12:00:26 -05:00
[uint16]$Tenant,
2020-12-08 12:00:26 -05:00
[object]$Role,
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2020-12-08 12:00:26 -05:00
[switch]$Raw
)
2021-07-23 16:19:03 -04:00
# $PSBoundParameters.Status = ValidateIPAMChoice -ProvidedValue $Status -VLANStatus
2021-07-23 16:19:03 -04:00
# if ($null -ne $Role) {
# $PSBoundParameters.Role = ValidateIPAMChoice -ProvidedValue $Role -IPAddressRole
# }
2020-12-08 12:00:26 -05:00
$segments = [System.Collections.ArrayList]::new(@('ipam', 'vlans'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-07-23 16:19:03 -04:00
if ($PSCmdlet.ShouldProcess($nae, 'Create new Vlan $($vid)')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters -Raw:$Raw
}
2020-12-08 12:00:26 -05:00
}
2023-02-16 09:49:13 -05:00
#endregion
#region File New-NetboxTenant.ps1
function New-NetboxTenant {
<#
.SYNOPSIS
Create a new tenant in Netbox
.DESCRIPTION
Creates a new tenant object in Netbox
.PARAMETER Name
The tenant name, e.g "Contoso Inc"
.PARAMETER Slug
The unique URL for the tenant. Can only contain hypens, A-Z, a-z, 0-9, and underscores
.PARAMETER Description
Short description of the tenant
.PARAMETER Custom_Fields
Hashtable of custom field values.
.PARAMETER Raw
Return the unparsed data from the HTTP request
.EXAMPLE
PS C:\> New-NetboxTenant -Name 'Contoso Inc' -Slug 'contoso-inc'
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateLength(1, 100)]
[string]$Name,
[Parameter(Mandatory = $true)]
[ValidateLength(1, 100)]
[ValidatePattern('^[-a-zA-Z0-9_]+$')]
[string]$Slug,
[ValidateLength(0, 200)]
[string]$Description,
[hashtable]$Custom_Fields,
[switch]$Raw
)
process {
$Segments = [System.Collections.ArrayList]::new(@('tenancy', 'tenants'))
$Method = 'POST'
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
$URI = BuildNewURI -Segments $URIComponents.Segments
if ($PSCmdlet.ShouldProcess($Address, 'Create new tenant')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters -Raw:$Raw
}
}
}
2020-12-08 12:00:26 -05:00
#endregion
#region File New-NetboxVirtualMachine.ps1
function New-NetboxVirtualMachine {
2021-07-23 16:19:03 -04:00
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true)]
[string]$Name,
2020-12-08 12:00:26 -05:00
[Parameter(Mandatory = $true)]
2022-12-06 13:35:56 -05:00
[uint16]$Site,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster,
2020-12-08 12:00:26 -05:00
[uint16]$Tenant,
2020-12-08 12:00:26 -05:00
[object]$Status = 'Active',
2020-12-08 12:00:26 -05:00
[uint16]$Role,
2020-12-08 12:00:26 -05:00
[uint16]$Platform,
2020-12-08 12:00:26 -05:00
[uint16]$vCPUs,
2020-12-08 12:00:26 -05:00
[uint16]$Memory,
2020-12-08 12:00:26 -05:00
[uint16]$Disk,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP4,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP6,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2020-12-08 12:00:26 -05:00
[string]$Comments
)
2021-07-23 16:19:03 -04:00
# $ModelDefinition = $script:NetboxConfig.APIDefinition.definitions.WritableVirtualMachineWithConfigContext
2021-07-23 16:19:03 -04:00
# # 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 ', '))
# }
2020-12-08 12:00:26 -05:00
#$PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
2022-12-06 13:35:56 -05:00
if ($PSBoundParameters.ContainsKey('Cluster') -and (-not $PSBoundParameters.ContainsKey('Site'))) {
throw "You must specify a site ID with a cluster ID"
}
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines'))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-07-23 16:19:03 -04:00
if ($PSCmdlet.ShouldProcess($name, 'Create new Virtual Machine')) {
InvokeNetboxRequest -URI $URI -Method POST -Body $URIComponents.Parameters
}
2020-12-08 12:00:26 -05:00
}
#endregion
#region File Remove-NetboxDCIMDevice.ps1
function Remove-NetboxDCIMDevice {
<#
.SYNOPSIS
Delete a device
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Deletes a device from Netbox by ID
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Database ID of the device
2020-12-08 12:00:26 -05:00
.PARAMETER Force
Force deletion without any prompts
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Remove-NetboxDCIMDevice -Id $value1
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2020-12-08 12:00:26 -05:00
begin {
2020-12-08 12:00:26 -05:00
}
2020-12-08 12:00:26 -05:00
process {
foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentDevice.Name) | ID: $($CurrentDevice.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File Remove-NetboxDCIMInterface.ps1
function Remove-NetboxDCIMInterface {
<#
.SYNOPSIS
Removes an interface
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Removes an interface by ID from a device
2020-12-08 12:00:26 -05:00
.PARAMETER Id
A description of the Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Force
A description of the Force parameter.
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Remove-NetboxDCIMInterface -Id $value1
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2020-12-08 12:00:26 -05:00
begin {
2020-12-08 12:00:26 -05:00
}
2020-12-08 12:00:26 -05:00
process {
foreach ($InterfaceId in $Id) {
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentInterface.Name) | ID: $($CurrentInterface.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File Remove-NetboxDCIMInterfaceConnection.ps1
function Remove-NetboxDCIMInterfaceConnection {
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
[OutputType([void])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2020-12-08 12:00:26 -05:00
begin {
2020-12-08 12:00:26 -05:00
}
2020-12-08 12:00:26 -05:00
process {
foreach ($ConnectionID in $Id) {
$CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($ConnectionID.Id)", "REMOVE")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
2022-12-06 13:35:56 -05:00
#region File Remove-NetboxDCIMSite.ps1
2020-12-08 12:00:26 -05:00
2021-03-30 11:00:53 -04:00
<#
2022-12-06 13:35:56 -05:00
.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: New-NetboxDCIMSite.ps1
===========================================================================
.DESCRIPTION
A description of the file.
2020-12-08 12:00:26 -05:00
#>
2022-12-06 13:35:56 -05:00
function Remove-NetboxDCIMSite {
<#
.SYNOPSIS
Remove a Site
.DESCRIPTION
Remove a DCIM Site from Netbox
.EXAMPLE
Remove-NetboxDCIMSite -Id 1
Remove DCM Site with id 1
.EXAMPLE
Get-NetboxDCIMSite -name My Site | Remove-NetboxDCIMSite -confirm:$false
Remove DCM Site with name My Site without confirmation
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint]$Id
)
begin {
}
process {
$CurrentSite = Get-NetboxDCIMSite -Id $Id -ErrorAction Stop
if ($pscmdlet.ShouldProcess("$($CurrentSite.Name)/$($CurrentSite.Id)", "Remove Site")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'sites', $CurrentSite.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
end {
}
}
#endregion
#region File Remove-NetboxIPAMAddress.ps1
2020-12-08 12:00:26 -05:00
function Remove-NetboxIPAMAddress {
2021-03-30 11:00:53 -04:00
<#
2020-12-08 12:00:26 -05:00
.SYNOPSIS
Remove an IP address from Netbox
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Removes/deletes an IP address from Netbox by ID and optional other filters
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Database ID of the IP address object.
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.PARAMETER Force
Do not confirm.
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Remove-NetboxIPAMAddress -Id $value1
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[CmdletBinding(ConfirmImpact = 'High',
2021-03-30 11:00:53 -04:00
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
param
(
[Parameter(Mandatory = $true,
2021-03-30 11:00:53 -04:00
ValueFromPipelineByPropertyName = $true)]
[int[]]$Id,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
process {
foreach ($IPId in $Id) {
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess($CurrentIP.Address, "Delete")) {
$URI = BuildNewURI -Segments $Segments
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
}
#endregion
#region File Remove-NetboxVirtualMachine.ps1
function Remove-NetboxVirtualMachine {
<#
.SYNOPSIS
Delete a virtual machine
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Deletes a virtual machine from Netbox by ID
2020-12-08 12:00:26 -05:00
.PARAMETER Id
Database ID of the virtual machine
2020-12-08 12:00:26 -05:00
.PARAMETER Force
Force deletion without any prompts
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Remove-NetboxVirtualMachine -Id $value1
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2020-12-08 12:00:26 -05:00
begin {
2020-12-08 12:00:26 -05:00
}
2020-12-08 12:00:26 -05:00
process {
foreach ($VMId in $Id) {
$CurrentVM = Get-NetboxVirtualMachine -Id $VMId -ErrorAction Stop
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentVM.Name)/$($CurrentVM.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $CurrentVM.Id))
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
2021-07-22 11:53:58 -04:00
#region File Set-NetboxCipherSSL.ps1
Function Set-NetboxCipherSSL {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")]
Param( )
# Hack for allowing TLS 1.1 and TLS 1.2 (by default it is only SSL3 and TLS (1.0))
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
}
#endregion
2020-12-08 12:00:26 -05:00
#region File Set-NetboxCredential.ps1
function Set-NetboxCredential {
[CmdletBinding(DefaultParameterSetName = 'CredsObject',
2021-07-22 11:53:58 -04:00
ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([pscredential])]
param
(
[Parameter(ParameterSetName = 'CredsObject',
2021-07-22 11:53:58 -04:00
Mandatory = $true)]
2020-12-08 12:00:26 -05:00
[pscredential]$Credential,
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
[Parameter(ParameterSetName = 'UserPass',
2021-07-22 11:53:58 -04:00
Mandatory = $true)]
2020-12-08 12:00:26 -05:00
[securestring]$Token
)
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
if ($PSCmdlet.ShouldProcess('Netbox Credentials', 'Set')) {
switch ($PsCmdlet.ParameterSetName) {
'CredsObject' {
$script:NetboxConfig.Credential = $Credential
break
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
'UserPass' {
$script:NetboxConfig.Credential = [System.Management.Automation.PSCredential]::new('notapplicable', $Token)
break
}
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$script:NetboxConfig.Credential
}
}
#endregion
#region File Set-NetboxDCIMDevice.ps1
function Set-NetboxDCIMDevice {
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[object]$Device_Role,
2020-12-08 12:00:26 -05:00
[object]$Device_Type,
2020-12-08 12:00:26 -05:00
[uint16]$Site,
2020-12-08 12:00:26 -05:00
[object]$Status,
2020-12-08 12:00:26 -05:00
[uint16]$Platform,
2020-12-08 12:00:26 -05:00
[uint16]$Tenant,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster,
2020-12-08 12:00:26 -05:00
[uint16]$Rack,
2020-12-08 12:00:26 -05:00
[uint16]$Position,
2020-12-08 12:00:26 -05:00
[object]$Face,
2020-12-08 12:00:26 -05:00
[string]$Serial,
2020-12-08 12:00:26 -05:00
[string]$Asset_Tag,
2020-12-08 12:00:26 -05:00
[uint16]$Virtual_Chassis,
2020-12-08 12:00:26 -05:00
[uint16]$VC_Priority,
2020-12-08 12:00:26 -05:00
[uint16]$VC_Position,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP4,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP6,
2020-12-08 12:00:26 -05:00
[string]$Comments,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2020-12-08 12:00:26 -05:00
begin {
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateDCIMChoice -ProvidedValue $Status -DeviceStatus
# }
2020-12-08 12:00:26 -05:00
# if ($null -ne $Face) {
# $PSBoundParameters.Face = ValidateDCIMChoice -ProvidedValue $Face -DeviceFace
# }
}
2020-12-08 12:00:26 -05:00
process {
foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File Set-NetboxDCIMInterface.ps1
function Set-NetboxDCIMInterface {
2021-07-23 16:19:03 -04:00
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
2021-07-23 16:19:03 -04:00
ValueFromPipelineByPropertyName = $true)]
2020-12-08 12:00:26 -05:00
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[uint16]$Device,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[bool]$Enabled,
2020-12-08 12:00:26 -05:00
[object]$Form_Factor,
2020-12-08 12:00:26 -05:00
[uint16]$MTU,
2020-12-08 12:00:26 -05:00
[string]$MAC_Address,
2020-12-08 12:00:26 -05:00
[bool]$MGMT_Only,
2020-12-08 12:00:26 -05:00
[uint16]$LAG,
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[ValidateSet('Access', 'Tagged', 'Tagged All', '100', '200', '300', IgnoreCase = $true)]
[string]$Mode,
2020-12-08 12:00:26 -05:00
[ValidateRange(1, 4094)]
[uint16]$Untagged_VLAN,
2020-12-08 12:00:26 -05:00
[ValidateRange(1, 4094)]
[uint16[]]$Tagged_VLANs
)
2020-12-08 12:00:26 -05:00
begin {
2021-07-23 16:19:03 -04:00
# if ($null -ne $Form_Factor) {
# $PSBoundParameters.Form_Factor = ValidateDCIMChoice -ProvidedValue $Form_Factor -InterfaceFormFactor
# }
2020-12-08 12:00:26 -05:00
if (-not [System.String]::IsNullOrWhiteSpace($Mode)) {
$PSBoundParameters.Mode = switch ($Mode) {
'Access' {
100
break
}
2020-12-08 12:00:26 -05:00
'Tagged' {
200
break
}
2020-12-08 12:00:26 -05:00
'Tagged All' {
300
break
}
2020-12-08 12:00:26 -05:00
default {
$_
}
}
}
}
2020-12-08 12:00:26 -05:00
process {
foreach ($InterfaceId in $Id) {
$CurrentInterface = Get-NetboxDCIMInterface -Id $InterfaceId -ErrorAction Stop
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interfaces', $CurrentInterface.Id))
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $Segments
2021-07-23 16:19:03 -04:00
if ($Force -or $pscmdlet.ShouldProcess("Interface ID $($CurrentInterface.Id)", "Set")) {
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
2020-12-08 12:00:26 -05:00
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File Set-NetboxDCIMInterfaceConnection.ps1
function Set-NetboxDCIMInterfaceConnection {
<#
.SYNOPSIS
Update an interface connection
2020-12-08 12:00:26 -05:00
.DESCRIPTION
Update an interface connection
2020-12-08 12:00:26 -05:00
.PARAMETER Id
A description of the Id parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Connection_Status
A description of the Connection_Status parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Interface_A
A description of the Interface_A parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Interface_B
A description of the Interface_B parameter.
2020-12-08 12:00:26 -05:00
.PARAMETER Force
A description of the Force parameter.
2020-12-08 12:00:26 -05:00
.EXAMPLE
PS C:\> Set-NetboxDCIMInterfaceConnection -Id $value1
2020-12-08 12:00:26 -05:00
.NOTES
Additional information about the function.
#>
2020-12-08 12:00:26 -05:00
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[object]$Connection_Status,
2020-12-08 12:00:26 -05:00
[uint16]$Interface_A,
2020-12-08 12:00:26 -05:00
[uint16]$Interface_B,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2020-12-08 12:00:26 -05:00
begin {
# if ($null -ne $Connection_Status) {
# $PSBoundParameters.Connection_Status = ValidateDCIMChoice -ProvidedValue $Connection_Status -InterfaceConnectionStatus
# }
2020-12-08 12:00:26 -05:00
if ((@($ID).Count -gt 1) -and ($Interface_A -or $Interface_B)) {
throw "Cannot set multiple connections to the same interface"
}
}
2020-12-08 12:00:26 -05:00
process {
foreach ($ConnectionID in $Id) {
$CurrentConnection = Get-NetboxDCIMInterfaceConnection -Id $ConnectionID -ErrorAction Stop
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'interface-connections', $CurrentConnection.Id))
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess("Connection ID $($CurrentConnection.Id)", "Set")) {
2020-12-08 12:00:26 -05:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File Set-NetboxHostName.ps1
function Set-NetboxHostName {
[CmdletBinding(ConfirmImpact = 'Low',
2021-07-22 11:53:58 -04:00
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
[OutputType([string])]
param
(
[Parameter(Mandatory = $true)]
[string]$Hostname
)
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
if ($PSCmdlet.ShouldProcess('Netbox Hostname', 'Set')) {
$script:NetboxConfig.Hostname = $Hostname.Trim()
$script:NetboxConfig.Hostname
}
}
#endregion
2021-03-31 10:24:08 -04:00
#region File Set-NetboxHostPort.ps1
function Set-NetboxHostPort {
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([string])]
param
(
[Parameter(Mandatory = $true)]
[uint16]$Port
)
2021-03-31 10:24:08 -04:00
if ($PSCmdlet.ShouldProcess('Netbox Port', 'Set')) {
$script:NetboxConfig.HostPort = $Port
$script:NetboxConfig.HostPort
}
}
#endregion
#region File Set-NetboxHostScheme.ps1
function Set-NetboxHostScheme {
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([string])]
param
(
[Parameter(Mandatory = $false)]
[ValidateSet('https', 'http', IgnoreCase = $true)]
[string]$Scheme = 'https'
)
2021-03-31 10:24:08 -04:00
if ($PSCmdlet.ShouldProcess('Netbox Host Scheme', 'Set')) {
if ($Scheme -eq 'http') {
Write-Warning "Connecting via non-secure HTTP is not-recommended"
}
2021-03-31 10:24:08 -04:00
$script:NetboxConfig.HostScheme = $Scheme
$script:NetboxConfig.HostScheme
}
}
#endregion
2021-07-22 11:53:58 -04:00
#region File Set-NetboxInvokeParams.ps1
function Set-NetboxInvokeParams {
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([string])]
param(
[Parameter(Mandatory = $true)]
[array]$InvokeParams
)
if ($PSCmdlet.ShouldProcess('Netbox Invoke Params', 'Set')) {
$script:NetboxConfig.InvokeParams = $InvokeParams
$script:NetboxConfig.InvokeParams
}
}
#endregion
2020-12-08 12:00:26 -05:00
#region File Set-NetboxIPAMAddress.ps1
function Set-NetboxIPAMAddress {
[CmdletBinding(ConfirmImpact = 'Medium',
2021-03-30 11:00:53 -04:00
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
param
(
[Parameter(Mandatory = $true,
2021-03-30 11:00:53 -04:00
ValueFromPipelineByPropertyName = $true)]
[int[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Address,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[string]$Status,
2021-03-30 11:00:53 -04:00
[int]$Tenant,
[int]$VRF,
2020-12-08 12:00:26 -05:00
[object]$Role,
2021-03-30 11:00:53 -04:00
[int]$NAT_Inside,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[ValidateSet('dcim.interface', 'virtualization.vminterface', IgnoreCase = $true)]
[string]$Assigned_Object_Type,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[uint16]$Assigned_Object_Id,
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
[string]$Description,
2021-03-30 11:00:53 -04:00
[string]$Dns_name,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
begin {
# Write-Verbose "Validating enum properties"
# $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0))
$Method = 'PATCH'
2021-03-30 11:00:53 -04:00
#
2020-12-08 12:00:26 -05:00
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
2021-03-30 11:00:53 -04:00
#
2020-12-08 12:00:26 -05:00
# 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]"
# }
# }
2021-03-30 11:00:53 -04:00
#
2020-12-08 12:00:26 -05:00
# Write-Verbose "Finished enum validation"
}
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
process {
foreach ($IPId in $Id) {
2021-03-25 16:45:40 -04:00
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"
2021-03-30 11:00:53 -04:00
}
elseif ((-not [string]::IsNullOrWhiteSpace($Assigned_Object_Type)) -and [string]::IsNullOrWhiteSpace($Assigned_Object_Id)) {
2021-03-25 16:45:40 -04:00
throw "Assigned_Object_Id is required when specifying Assigned_Object_Type"
}
2020-12-08 12:00:26 -05:00
}
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', $IPId))
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
Write-Verbose "Obtaining IP from ID $IPId"
$CurrentIP = Get-NetboxIPAMAddress -Id $IPId -ErrorAction Stop
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
if ($Force -or $PSCmdlet.ShouldProcess($CurrentIP.Address, 'Set')) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-03-30 11:00:53 -04:00
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
}
}
}
}
2021-03-25 16:45:40 -04:00
#endregion
#region File Set-NetboxIPAMPrefix.ps1
function Set-NetboxIPAMPrefix {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2021-03-25 16:45:40 -04:00
[string]$Prefix,
2021-03-25 16:45:40 -04:00
[string]$Status,
2021-03-25 16:45:40 -04:00
[uint16]$Tenant,
2021-03-25 16:45:40 -04:00
[uint16]$Site,
2021-03-25 16:45:40 -04:00
[uint16]$VRF,
2021-03-25 16:45:40 -04:00
[uint16]$VLAN,
2021-03-25 16:45:40 -04:00
[object]$Role,
2021-03-25 16:45:40 -04:00
[hashtable]$Custom_Fields,
2021-03-25 16:45:40 -04:00
[string]$Description,
2021-03-25 16:45:40 -04:00
[switch]$Is_Pool,
2021-03-25 16:45:40 -04:00
[switch]$Force
)
2021-03-25 16:45:40 -04:00
begin {
# Write-Verbose "Validating enum properties"
# $Segments = [System.Collections.ArrayList]::new(@('ipam', 'ip-addresses', 0))
$Method = 'PATCH'
#
2021-03-25 16:45:40 -04:00
# # Value validation
# $ModelDefinition = GetModelDefinitionFromURIPath -Segments $Segments -Method $Method
# $EnumProperties = GetModelEnumProperties -ModelDefinition $ModelDefinition
#
2021-03-25 16:45:40 -04:00
# 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]"
# }
# }
#
2021-03-25 16:45:40 -04:00
# Write-Verbose "Finished enum validation"
}
2021-03-25 16:45:40 -04:00
process {
foreach ($PrefixId in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('ipam', 'prefixes', $PrefixId))
2021-03-25 16:45:40 -04:00
Write-Verbose "Obtaining Prefix from ID $PrefixId"
$CurrentPrefix = Get-NetboxIPAMPrefix -Id $PrefixId -ErrorAction Stop
2021-03-25 16:45:40 -04:00
if ($Force -or $PSCmdlet.ShouldProcess($CurrentPrefix.Prefix, 'Set')) {
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2021-03-25 16:45:40 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-03-25 16:45:40 -04:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method $Method
}
}
}
}
2021-07-22 11:53:58 -04:00
#endregion
#region File Set-NetboxTimeout.ps1
function Set-NetboxTimeout {
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([uint16])]
param
(
[Parameter(Mandatory = $false)]
[ValidateRange(1, 65535)]
[uint16]$TimeoutSeconds = 30
)
if ($PSCmdlet.ShouldProcess('Netbox Timeout', 'Set')) {
$script:NetboxConfig.Timeout = $TimeoutSeconds
$script:NetboxConfig.Timeout
}
}
#endregion
#region File Set-NetboxUnstrustedSSL.ps1
Function Set-NetboxUntrustedSSL {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessforStateChangingFunctions", "")]
Param( )
# Hack for allowing untrusted SSL certs with https connections
Add-Type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy
}
2020-12-08 12:00:26 -05:00
#endregion
#region File Set-NetboxVirtualMachine.ps1
function Set-NetboxVirtualMachine {
[CmdletBinding(ConfirmImpact = 'Medium',
2021-07-23 16:19:03 -04:00
SupportsShouldProcess = $true)]
2020-12-08 12:00:26 -05:00
param
(
[Parameter(Mandatory = $true,
2021-07-23 16:19:03 -04:00
ValueFromPipelineByPropertyName = $true)]
2020-12-08 12:00:26 -05:00
[uint16]$Id,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[uint16]$Role,
2020-12-08 12:00:26 -05:00
[uint16]$Cluster,
2020-12-08 12:00:26 -05:00
[object]$Status,
2020-12-08 12:00:26 -05:00
[uint16]$Platform,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP4,
2020-12-08 12:00:26 -05:00
[uint16]$Primary_IP6,
2020-12-08 12:00:26 -05:00
[byte]$VCPUs,
2020-12-08 12:00:26 -05:00
[uint16]$Memory,
2020-12-08 12:00:26 -05:00
[uint16]$Disk,
2020-12-08 12:00:26 -05:00
[uint16]$Tenant,
2020-12-08 12:00:26 -05:00
[string]$Comments,
2020-12-08 12:00:26 -05:00
[hashtable]$Custom_Fields,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2021-07-23 16:19:03 -04:00
# if ($null -ne $Status) {
# $PSBoundParameters.Status = ValidateVirtualizationChoice -ProvidedValue $Status -VirtualMachineStatus
# }
2021-07-23 16:19:03 -04:00
process {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-machines', $Id))
2021-07-23 16:19:03 -04:00
Write-Verbose "Obtaining VM from ID $Id"
2021-07-23 16:19:03 -04:00
#$CurrentVM = Get-NetboxVirtualMachine -Id $Id -ErrorAction Stop
2021-07-23 16:19:03 -04:00
Write-Verbose "Finished obtaining VM"
2021-07-23 16:19:03 -04:00
if ($Force -or $pscmdlet.ShouldProcess($ID, "Set properties on VM ID")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2021-07-23 16:19:03 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2021-07-23 16:19:03 -04:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File Set-NetboxVirtualMachineInterface.ps1
function Set-NetboxVirtualMachineInterface {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-12-08 12:00:26 -05:00
[string]$Name,
2020-12-08 12:00:26 -05:00
[string]$MAC_Address,
2020-12-08 12:00:26 -05:00
[uint16]$MTU,
2020-12-08 12:00:26 -05:00
[string]$Description,
2020-12-08 12:00:26 -05:00
[boolean]$Enabled,
2020-12-08 12:00:26 -05:00
[uint16]$Virtual_Machine,
2020-12-08 12:00:26 -05:00
[switch]$Force
)
2020-12-08 12:00:26 -05:00
begin {
2020-12-08 12:00:26 -05:00
}
2020-12-08 12:00:26 -05:00
process {
foreach ($VMI_ID in $Id) {
Write-Verbose "Obtaining VM Interface..."
$CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop
Write-Verbose "Finished obtaining VM Interface"
2020-12-08 12:00:26 -05:00
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id))
2020-12-08 12:00:26 -05:00
if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2020-12-08 12:00:26 -05:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
2020-12-08 12:00:26 -05:00
end {
2020-12-08 12:00:26 -05:00
}
}
#endregion
#region File SetupNetboxConfigVariable.ps1
function SetupNetboxConfigVariable {
[CmdletBinding()]
param
(
[switch]$Overwrite
)
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
Write-Verbose "Checking for NetboxConfig hashtable"
if ((-not ($script:NetboxConfig)) -or $Overwrite) {
Write-Verbose "Creating NetboxConfig hashtable"
$script:NetboxConfig = @{
2021-07-22 11:53:58 -04:00
'Connected' = $false
'Choices' = @{
2020-12-08 12:00:26 -05:00
}
'APIDefinition' = $null
}
}
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
Write-Verbose "NetboxConfig hashtable already exists"
}
#endregion
#region File VerifyAPIConnectivity.ps1
function VerifyAPIConnectivity {
[CmdletBinding()]
param ()
2021-07-22 11:53:58 -04:00
2020-12-08 12:00:26 -05:00
$uriSegments = [System.Collections.ArrayList]::new(@('extras'))
2021-07-22 11:53:58 -04:00
$uri = BuildNewURI -Segments $uriSegments -Parameters @{'format' = 'json' } -SkipConnectedCheck
2020-12-08 12:00:26 -05:00
InvokeNetboxRequest -URI $uri
}
#endregion
2021-07-23 10:26:14 -04:00
# Build a list of common parameters so we can omit them to build URI parameters
2020-12-08 12:00:26 -05:00
$script:CommonParameterNames = New-Object System.Collections.ArrayList
[void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::CommonParameters))
[void]$script:CommonParameterNames.AddRange(@([System.Management.Automation.PSCmdlet]::OptionalCommonParameters))
[void]$script:CommonParameterNames.Add('Raw')
SetupNetboxConfigVariable