r/PowerShell • u/xipodu • Apr 11 '26
Question Powershell + Visio
How would you approach solving the following using PowerShell: creating a Visio diagram based on data from JSON?
The examples I’ve seen typically rely on Visio being installed locally and use file-based approaches. As far as I know, there isn’t an open API in Microsoft 365 for this, but I may have missed something.
Perhaps create drawio file convert it to visio
24
Upvotes
25
u/KevMar Community Blogger Apr 11 '26
Does it need to be Visio or just a diagram?
I created a powershell model to dynamically generate diagrams called PSGraph. I haven't really been maintaining it, so I hope it still works. But I wrote it specifically for this. https://psgraph.readthedocs.io/en/latest/Example-Scripted/
It's really just a wrapper around graphviz so that's also required to be installed. I think my docs cover how to get started.
14
u/shutchomouf Apr 11 '26
Another option is Mermaid for diagramming
11
u/ZenoArrow Apr 11 '26 edited Apr 11 '26
Visio files are just XML under the hood, if you're sure that you don't want to make things easy on yourself by installing Visio (as you could then use libraries like https://saveenr.gitbook.io/visiopowershell ), then you could manipulate the structure of XML using PowerShell, it's fairly good at that.
Here's a general guide that should help you: https://learn.microsoft.com/en-us/office/client-developer/visio/how-to-manipulate-the-visio-file-format-programmatically
Here's the XML schema I'd recommend working with: https://learn.microsoft.com/en-us/office/client-developer/visio/schema-mapvisio-xml
There's also the Aspose.Diagram library, which can create Visio diagrams and doesn't seem to have a dependency on Visio being installed, but it's very expensive (over $1000 per year), so I wouldn't recommend it (it's cheaper to buy Visio): https://kb.aspose.com/diagram/net/create-visio-diagram-in-csharp/
2
u/Trakeen Apr 11 '26
I do this with drawio and some claude skills. Works reasonably well
2
u/Proxiconn Apr 12 '26
We write the table structures that Visio can import and create diagrams from.
2
u/Excellent-Average782 Apr 13 '26
You're right, no M365 API for Visio. PowerShell can generate draw.io XML from JSON pretty easily. Or consider web-based tools like Miro that have APIs for programmatic diagram creation from data.
1
u/xipodu Apr 11 '26
Drawio is great and easy, just want for this project use Visio.
4
u/Pixelgordo Apr 11 '26
I don't have visio installed in my computer, so I can't be sure about this, but try something like:
$visio = New-Object -ComObject Visio.Application $visio.Visible = $true $doc = $visio.Documents.Add("") $page = $visio.ActivePage
If this works you have it. Explore de COM of the document, or create a document with the kind of data you want, and using get-member explore the data you need.
With this approach I work with word, excel and PowerPoint flawlessly.
2
u/ostekages Apr 11 '26
I'm not sure visio supports this, but can confirm that drawio does. It's just XML(or technically their own file extension).
2
u/Hefty-Possibility625 Apr 15 '26
I use kroki.io for this since it has support for mermaid, plantUML, graphviz and a whole bunch more. Send the diagram code in a POST request and you get back an image file.
Documentation: https://docs.kroki.io/kroki/setup/usage/
1
u/SamfromLucidSoftware Apr 14 '26
Generating diagrams from JSON is actually pretty doable if the tool you’re using has a proper API or data import support built in. The PowerShell piece just becomes a call to that API with your structured data.
Might be worth exploring tools that support data-driven diagram generation natively, it tends to be a much cleaner pipeline than file-based approaches. Just sayin!