Skip to content

Latest commit

 

History

History
350 lines (247 loc) · 7.35 KB

File metadata and controls

350 lines (247 loc) · 7.35 KB

DCIM Examples

Examples for Data Center Infrastructure Management (DCIM) operations.

Sites

List All Sites

Get-NBDCIMSite

Create a Site

New-NBDCIMSite -Name 'Amsterdam DC' -Slug 'amsterdam-dc' -Status 'active'

Update a Site

Set-NBDCIMSite -Id 1 -Description 'Primary datacenter in Amsterdam'

Devices

List All Devices

Get-NBDCIMDevice

Get Device by Name

Get-NBDCIMDevice -Name 'server01'

Get Devices by Site

Get-NBDCIMDevice -Site 1

Get Active Devices

Get-NBDCIMDevice -Status 'active'

Create a Device

$params = @{
    Name        = 'server01'
    Device_Type = 1      # Device type ID
    Site        = 1      # Site ID
    Role        = 1      # Device role ID
    Status      = 'active'
}
New-NBDCIMDevice @params

Update Device Status

Set-NBDCIMDevice -Id 1 -Status 'offline'

Delete a Device

Remove-NBDCIMDevice -Id 1 -Confirm

Interfaces

Get Device Interfaces

Get-NBDCIMInterface -Device_Id 1

Create an Interface

New-NBDCIMInterface -Name 'eth0' -Device 1 -Type '1000base-t'

Update Interface

Set-NBDCIMInterface -Id 1 -Enabled $true -Description 'Management interface'

Racks

List Racks in a Site

Get-NBDCIMRack -Site 1

Create a Rack

New-NBDCIMRack -Name 'Rack-A01' -Site 1 -U_Height 42 -Status 'active'

Get Rack with Devices

$rack = Get-NBDCIMRack -Id 1
Get-NBDCIMDevice -Rack $rack.id

Rack Elevation

PowerNetbox provides functions to visualize rack elevations in various formats.

Get Rack Elevation Data

# Get elevation data for a rack (JSON)
Get-NBDCIMRackElevation -Id 24

# Get rear face elevation
Get-NBDCIMRackElevation -Id 24 -Face rear

# Get all elevation units (auto-pagination)
Get-NBDCIMRackElevation -Id 24 -All

# Get only occupied units
Get-NBDCIMRackElevation -Id 24 -All | Where-Object { $_.device }

Get Native SVG Rendering

# Get Netbox's native SVG rendering
$svg = Get-NBDCIMRackElevation -Id 24 -Render svg

# Save SVG to file
$svg | Out-File -Path './rack.svg'

Export to Console (ASCII Art)

# Display rack elevation in terminal with colors
Export-NBRackElevation -Id 24 -Format Console

# Compact view (hides empty slots)
Export-NBRackElevation -Id 24 -Format Console -Compact

# Without ANSI colors (for logging/piping)
Export-NBRackElevation -Id 24 -Format Console -NoColor

# Show both front and rear faces
Export-NBRackElevation -Id 24 -Format Console -Face Both -Compact

Example console output:

╔═════════════════════════════════════════════════════════╗
║              Amsterdam-R01 - Front Face                  ║
║          Site: Amsterdam DC | Height: 42U                ║
╠════╦════════════════════════════════════════════════════╣
║    ║ ... (40 empty slots) ...                           ║
║   2 ║  switch-01                                         ║
║   1 ║  firewall-01                                       ║
╚════╩════════════════════════════════════════════════════╝
Generated by PowerNetbox | 2026-01-02 09:00

Export to HTML

# Generate HTML and save to file
Export-NBRackElevation -Id 24 -Format HTML -Path './rack.html'

# Generate HTML with native Netbox SVG
Export-NBRackElevation -Id 24 -Format HTML -UseNativeRenderer -Path './rack.html'

# Get HTML as string
$html = Export-NBRackElevation -Id 24 -Format HTML

Export to Markdown

# Generate GitHub-flavored Markdown
Export-NBRackElevation -Id 24 -Format Markdown

# Save to file
Export-NBRackElevation -Id 24 -Format Markdown -Path './rack.md'

# Include all empty slots in table
Export-NBRackElevation -Id 24 -Format Markdown -IncludeEmptySlots

Export to SVG

# Use Netbox's native SVG renderer
Export-NBRackElevation -Id 24 -Format SVG -Path './rack.svg'

Batch Export All Racks

# Export all racks in a site to HTML files
$outputDir = './rack-reports'
New-Item -ItemType Directory -Path $outputDir -Force

Get-NBDCIMRack -Site 1 | Export-NBRackElevation -Format HTML -Path $outputDir

# Export all racks as Markdown
Get-NBDCIMRack | ForEach-Object {
    $filename = "./racks/$($_.name -replace '[^\w\-]', '_').md"
    Export-NBRackElevation -Id $_.id -Format Markdown -Path $filename -Force
}

Pipeline Support

# Pipeline from Get-NBDCIMRack
Get-NBDCIMRack -Name 'Rack-A01' | Export-NBRackElevation -Format Console

# Export multiple racks
Get-NBDCIMRack -Site 1 | Export-NBRackElevation -Format HTML -Path './racks/' -Force

Parameters Reference

Parameter Description
-Id Rack ID (required, accepts pipeline)
-Format Output format: HTML, Markdown, SVG, Console (default: HTML)
-Face Rack face: Front, Rear, Both (default: Front)
-Path Output file path or directory
-UseNativeRenderer Use Netbox's built-in SVG renderer
-IncludeEmptySlots Include empty rack units in output
-Compact Console only: hide empty slots, show summary
-NoColor Console only: disable ANSI color codes
-PassThru Return content even when writing to file
-Force Overwrite existing files

Cables

List All Cables

Get-NBDCIMCable

Create a Cable

$params = @{
    A_Terminations = @(@{object_type = 'dcim.interface'; object_id = 1})
    B_Terminations = @(@{object_type = 'dcim.interface'; object_id = 2})
    Type           = 'cat6'
    Status         = 'connected'
}
New-NBDCIMCable @params

Locations & Regions

Create a Region

New-NBDCIMRegion -Name 'Europe' -Slug 'europe'

Create a Location

New-NBDCIMLocation -Name 'Floor 1' -Slug 'floor-1' -Site 1

Manufacturers & Device Types

List Manufacturers

Get-NBDCIMManufacturer

Create a Manufacturer

New-NBDCIMManufacturer -Name 'Dell' -Slug 'dell'

List Device Types

Get-NBDCIMDeviceType

Get Device Types by Manufacturer

Get-NBDCIMDeviceType -Manufacturer 1

Platforms

List Platforms

Get-NBDCIMPlatform

Create a Platform

New-NBDCIMPlatform -Name 'Ubuntu 22.04' -Slug 'ubuntu-22-04'

Bulk Operations

Export All Devices to CSV

Get-NBDCIMDevice |
    Select-Object name, @{N='site';E={$_.site.name}}, status, serial |
    Export-Csv -Path 'devices.csv' -NoTypeInformation

Update Multiple Devices

# Set all devices in site to maintenance
Get-NBDCIMDevice -Site 1 | ForEach-Object {
    Set-NBDCIMDevice -Id $_.id -Status 'planned'
}

Count Devices per Site

Get-NBDCIMDevice |
    Group-Object { $_.site.name } |
    Select-Object Name, Count |
    Sort-Object Count -Descending