Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Functions/DCIM/Devices/New-NetboxDCIMDeviceRole.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

function New-NetboxDCIMDeviceRole {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[string]$Name,

[string]$Color,

[bool]$VM_Role,

[string]$Description,

[hashtable]$Custom_Fields
)

$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-roles'))
$Method = 'POST'

if (-not $PSBoundParameters.ContainsKey('slug')) {
$PSBoundParameters.Add('slug', (GenerateSlug -Slug $Name))
}

$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters

$URI = BuildNewURI -Segments $URIComponents.Segments

if ($PSCmdlet.ShouldProcess($Name, 'Create new Device Role')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters
}
}
51 changes: 51 additions & 0 deletions Functions/DCIM/Devices/New-NetboxDCIMDeviceType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

function New-NetboxDCIMDeviceType {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
#region Parameters
param
(
[Parameter(Mandatory = $true)]
[string]$Manufacturer,

[Parameter(Mandatory = $true)]
[string]$Model,

[string]$Part_Number,

[uint16]$U_Height,

[bool]$Is_Full_Depth,

[string]$Subdevice_Role,

[string]$Airflow,

[uint16]$Weight,

[string]$Weight_Unit,

[string]$Description,

[string]$Comments,

[hashtable]$Custom_Fields
)
#endregion Parameters

$Segments = [System.Collections.ArrayList]::new(@('dcim', 'device-types'))
$Method = 'POST'

if (-not $PSBoundParameters.ContainsKey('slug')) {
$PSBoundParameters.Add('slug', (GenerateSlug -Slug $Model))
}

$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters

$URI = BuildNewURI -Segments $URIComponents.Segments

if ($PSCmdlet.ShouldProcess($Name, 'Create new Device Types')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters
}
}
50 changes: 50 additions & 0 deletions Functions/DCIM/Manufacture/Get-NetboxDCIMDManufacture.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

function Get-NetboxDCIMManufacture {
[CmdletBinding()]
#region Parameters
param
(
[uint16]$Offset,

[uint16]$Limit,

[Parameter(ParameterSetName = 'ById')]
[uint16[]]$Id,

[string]$Name,

[string]$Slug,

[switch]$Raw
)
#endregion Parameters

switch ($PSCmdlet.ParameterSetName) {
'ById' {
foreach ($ManuID in $Id) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'manufacturers', $ManuID))

$URIComponents = BuildURIComponents -URISegments $Segments -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Raw'

$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters

InvokeNetboxRequest -URI $URI -Raw:$Raw
}

break
}

default {

$Segments = [System.Collections.ArrayList]::new(@('dcim', 'manufacturers'))

$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw'

$URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters

InvokeNetboxRequest -URI $URI -Raw:$Raw

}
}

}
33 changes: 33 additions & 0 deletions Functions/DCIM/Manufacture/New-NetboxDCIMManufacture.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

function New-NetboxDCIMManufacture {
[CmdletBinding(ConfirmImpact = 'low',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
#region Parameters
param
(
[Parameter(Mandatory = $true)]
[string]$Name,

[string]$Description,

[hashtable]$Custom_Fields

)
#endregion Parameters

$Segments = [System.Collections.ArrayList]::new(@('dcim', 'manufacturers'))
$Method = 'POST'

if (-not $PSBoundParameters.ContainsKey('slug')) {
$PSBoundParameters.Add('slug', (GenerateSlug -Slug $name))
}

$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters

$URI = BuildNewURI -Segments $URIComponents.Segments

if ($PSCmdlet.ShouldProcess($Name, 'Create new Manufacture')) {
InvokeNetboxRequest -URI $URI -Method $Method -Body $URIComponents.Parameters
}
}
14 changes: 10 additions & 4 deletions Functions/Helpers/BuildNewURI.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

function BuildNewURI {
<#
<#
.SYNOPSIS
Create a new URI for Netbox

Expand Down Expand Up @@ -52,11 +52,17 @@ function BuildNewURI {
$null = CheckNetboxIsConnected
}

# Begin a URI builder with HTTP/HTTPS and the provided hostname
$uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort)
# Begin a URI builder with HTTP/HTTPS and the provided hostname, and url path if required
if (-not $script:NetboxConfig.URLPath) {
throw "Netbox Credentials not set! You may set with Set-NetboxCredential"
$uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort)
} else {
$uriBuilder = [System.UriBuilder]::new($script:NetboxConfig.HostScheme, $script:NetboxConfig.Hostname, $script:NetboxConfig.HostPort, "/$($script:NetboxConfig.URLPath.trim('/'))")
}


# Generate the path by trimming excess slashes and whitespace from the $segments[] and joining together
$uriBuilder.Path = "api/{0}/" -f ($Segments.ForEach({
$uriBuilder.Path += "/api/{0}/" -f ($Segments.ForEach({
$_.trim('/').trim()
}) -join '/')

Expand Down
16 changes: 16 additions & 0 deletions Functions/Helpers/GenerateSlug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function GenerateSlug {
[CmdletBinding()]
[OutputType([string])]
param (
[Parameter(Mandatory = $true)]
[string]$Slug
)

Write-Verbose "Generating slug"

$Slug = $Slug.Replace("-", "").Replace(" ", "-").ToLower()

Write-Verbose " Completed building URIBuilder"
# Return the entire UriBuilder object
$Slug
}
19 changes: 10 additions & 9 deletions Functions/Setup/Connect-NetboxAPI.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function Connect-NetboxAPI {
<#
<#
.SYNOPSIS
Connects to the Netbox API and ensures Credential work properly

Expand Down Expand Up @@ -40,7 +40,7 @@
param
(
[Parameter(ParameterSetName = 'Manual',
Mandatory = $true)]
Mandatory = $true)]
[string]$Hostname,

[Parameter(Mandatory = $false)]
Expand All @@ -54,7 +54,7 @@
[uint16]$Port = 443,

[Parameter(ParameterSetName = 'URI',
Mandatory = $true)]
Mandatory = $true)]
[string]$URI,

[Parameter(Mandatory = $false)]
Expand Down Expand Up @@ -112,6 +112,7 @@
$null = Set-NetboxCredential -Credential $Credential
$null = Set-NetboxHostScheme -Scheme $uriBuilder.Scheme
$null = Set-NetboxHostPort -Port $uriBuilder.Port
$null = Set-NetboxURLPath -Path $uriBuilder.Path
$null = Set-NetboxInvokeParams -invokeParams $invokeParams
$null = Set-NetboxTimeout -TimeoutSeconds $TimeoutSeconds

Expand All @@ -128,12 +129,12 @@
}
}

# 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 "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"
Expand Down
11 changes: 11 additions & 0 deletions Functions/Setup/Get-NetboxURLPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Get-NetboxURLPath {
[CmdletBinding()]
param ()

Write-Verbose "Getting Netbox URL Path"
if ($null -eq $script:NetboxConfig.URLPath) {
throw "Netbox URL Path is not set! You may set it with Set-NetboxURLPath -Path 'netbox/'"
}

$script:NetboxConfig.URLPath
}
15 changes: 15 additions & 0 deletions Functions/Setup/Set-NetboxURLPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function Set-NetboxURLPath {
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
[OutputType([string])]
param
(
[Parameter(Mandatory = $true)]
[string]$Path
)

if ($PSCmdlet.ShouldProcess('Netbox URL Path', 'Set')) {
$script:NetboxConfig.URLPath = $Path.Trim()
$script:NetboxConfig.URLPath
}
}
Loading