Skip to content
Merged
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
21 changes: 20 additions & 1 deletion examples/New-NetworkDiagram.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ param(
[string]$OutputPath = '.\my-network.drawio'
)

function Get-WizardInventoryPath {
param([Parameter(Mandatory)][string]$OutputPath)

$outputDirectory = [System.IO.Path]::GetDirectoryName($OutputPath)
$outputBaseName = [System.IO.Path]::GetFileNameWithoutExtension($OutputPath)

if ([string]::IsNullOrEmpty($outputBaseName)) {
$outputBaseName = [System.IO.Path]::GetFileName($OutputPath)
}

$inventoryFileName = "$outputBaseName-inventory.json"
if ([string]::IsNullOrEmpty($outputDirectory)) {
return $inventoryFileName
}

return (Join-Path $outputDirectory $inventoryFileName)
}

$inventoryPath = Get-WizardInventoryPath -OutputPath $OutputPath

# ── IPv4 CIDR helpers ────────────────────────────────────────────────────────
# Real prefix-aware host enumeration (replaces the old /24-only "first 3 octets"
# assumption). Works for any prefix; the caller caps how many hosts get scanned.
Expand Down Expand Up @@ -491,7 +511,6 @@ if (Test-Path $OutputPath) {
}

# Save inventory for future use
$inventoryPath = $OutputPath -replace '\.drawio$', '-inventory.json'
$inventoryData = @{
knownDevices = @($nodes | ForEach-Object {
@{
Expand Down
16 changes: 16 additions & 0 deletions tests/NetDiagram.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,20 @@ Describe 'Quick-start wizard CIDR math (#4 regression)' {
$targets = @(Get-SubnetScanTarget -NetworkValue $net -BroadcastValue $bc -ScanDepth 'Full')
$targets.Count | Should -Be 0
}

It 'Builds a sibling inventory path for a .xml output path' {
$outputPath = Join-Path $script:TestDataPath 'office.xml'
$inventoryPath = Get-WizardInventoryPath -OutputPath $outputPath

$inventoryPath | Should -Be (Join-Path $script:TestDataPath 'office-inventory.json')
$inventoryPath | Should -Not -Be $outputPath
}

It 'Builds a sibling inventory path for an extensionless output path' {
$outputPath = Join-Path $script:TestDataPath 'office'
$inventoryPath = Get-WizardInventoryPath -OutputPath $outputPath

$inventoryPath | Should -Be (Join-Path $script:TestDataPath 'office-inventory.json')
$inventoryPath | Should -Not -Be $outputPath
}
}
Loading