Skip to content

Wizard overwrites the diagram with the inventory JSON when -OutputPath does not end in .drawio #9

Closed

Description

@jacobyoby

What

examples/New-NetworkDiagram.ps1:494 derives the inventory path with:

$inventoryPath = $OutputPath -replace '\.drawio$', '-inventory.json'

If the user passes an output path without a .drawio suffix (for example -OutputPath .\office.xml or -OutputPath .\office), the regex does not match and $inventoryPath equals $OutputPath. Line 514 then runs Out-File -FilePath $inventoryPath -Force, which replaces the draw.io XML written at line 486 with the inventory JSON. The summary at lines 528 to 532 still tells the user two files were produced.

The -OutputPath parameter (line 31) has no validation and the README advertises it as a free-form path.

Why it matters

The scan result is silently destroyed after a scan that can take minutes on -ScanDepth Full. The user sees a success banner and only finds out when draw.io refuses the file.

Done when

  • The inventory path is built with [System.IO.Path]::ChangeExtension or an explicit check, so it never equals $OutputPath.
  • Either -OutputPath is validated to end in .drawio, or a non-.drawio path is accepted and the inventory is still written to a distinct sibling file.
  • The path-derivation logic is moved above the if ($MyInvocation.InvocationName -eq '.') { return } guard (line 106) so the existing dot-sourcing pattern in tests/NetDiagram.Tests.ps1:586 can cover it with a Pester case for a .xml and an extensionless path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingeffort:S

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions