Every good blog post should have some real life story to help you visualise why things happen so here goes:
The Story
One day whilst sat in the office updating the disaster recovery documentation I needed to document the Virtual Infrastructure, we all know that managers like pretty pictures so the first thing they asked for was a pretty diagram of how the infrastructure looked.
After dropping my 40th VM object on the page I started to get a bit bored, i looked at other options. There is already a great tool on the market that performs this job, Veeam Reporter produces multiple documents and does a great job, but being a contractor I have a nil budget. Knowing that you can do some very cool things with Powershell I wondered how easy it would be to hook into the Visio com object to get powershell to create the document for me.
As it turns out it wasn’t that hard, there were a few sticky moments where I had to refer to the Visio forums, and a great starting point by the only powershell reference using Visio I could find (Check out CommandBreak_ Thanks Joeseph) after explaining what powershell was to the guys in the Visio Forum and explaining why I was using powershell as I think this is the first time these people had heard of it, I started to relate some of there c# examples back into powershell.
The Result
The result is by no means a totally polished all singing all dancing documenter that documents your VI from the left, from the right and upside down but what it is, is an example of what you can do with the Visio COM objects and powershell combined.
I have not yet included all the options I would like, in future versions I would like to be able to document the networking setup / storage paths etc but I’m working on something else so wanted to get this script out into the public.
Instructions
You will need:
- Powershell V1 (I haven’t tried it on V2 yet)
- The VI Toolkit
- Microsoft Visio (I have only tried 2003 +)
How to use:
- Download the zip file from the bottom of this page
- Once extracted copy the ‘My-VI-Shapes.vss‘ file to your ‘My Documents\My Shapes’ folder. If the folder does not exist create it and copy the file in.
- Run the powershell script with the following options:
To diagram the entire Infrastructure:
vDiagram.ps1 –VIServer MYVISERVER
To diagram a specific cluster use the following:
vDiagram.ps1 –VIServer MYVISERVER -Cluster “Production Cluster’
Example Output

The Download
This project has now moved to Github so please do add any changes you have back to the project for everyone to take advantage of here: https://github.com/alanrenouf/VisioPowerShell
i get this as well
This helped. Script worked just fine after using above suggestion
can some one help me on this script. I am getting few errors while running this script.
Hi Alan, I am getting few errors while running this script. could you please help me on this
Thanks Alan, great work.
Sorry about that, link updated!
Sorry about that, link updated!
Sorry about that, link updated!
Hi Alan, the link to the download doesn’t seem to work.
Also cannot access the download link?
Hi Alan, the link to the download doesn’t seem to work.
Hi Alan
I love the script but I am finding it creates a visio diagram with 4 of each host an d 4 of each VM. I haven’t been able to find out why. If I could get it to just show one of each it would be perfect! Where is the script would it be doing this 4 times each?Thank you
Hello
Is new script with OS version, IP address (Nic1), MemoryGB, NumCPU parameters awailable
Great script, it’s working for me on Visio 2013. Excellent work !
On line 42 change $item to $item.name. Worked for me on Visio 2016.
I love this script, question, when I run it, I cannot get it to populate the server names, below is the error:
Exception setting “Text”: Cannot convert the “SRVFORMS01” value of type “VirtualMachineImpl” to type “string”.
Please advise on any solution you may have.
Did you find a way to add the VM guest (OS version, IP address (Nic1), MemoryGB, NumCPU) when it is doing the visio diagram?
Erf… fail… Figured it out.
It was was after the stencils under my admin profile (runas).
Hi Alan,
I get these errors when I run the script:
PowerCLI C:\temp> .\vDiagram01.ps1 -VIServer vc01.neverland.local
Connecting to vc01.neverland.local
Exception calling “Add” with “1” argument(s): ”
File not found.”
At C:\temp\vDiagram01.ps1:62 char:34
+ $stnObj = $AppVisio.Documents.Add <<<< ($stnPath + $shpFile)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:63 char:30
+ $VCObj = $stnObj.Masters.Item <<<< ("Virtual Center Management Console")
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:64 char:32
+ $HostObj = $stnObj.Masters.Item <<<< ("ESX Host")
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:65 char:30
+ $MSObj = $stnObj.Masters.Item <<<< ("Microsoft Server")
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:66 char:30
+ $LXObj = $stnObj.Masters.Item <<<< ("Linux Server")
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:67 char:34
+ $OtherObj = $stnObj.Masters.Item <<<< ("Other Server")
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:68 char:31
+ $CluShp = $stnObj.Masters.Item <<<< ("Cluster")
+ CategoryInfo : InvalidOperation: (Item:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : InvokeMethodOnNull
Adding vc01.neverland.local
Exception calling "Drop" with "3" argument(s): "
An exception occurred."
At C:\temp\vDiagram01.ps1:40 char:27
+ $shpObj = $pagObj.Drop <<<< ($mastObj, $x, $y)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Property 'Text' cannot be found on this object; make sure it exists and is sett
able.
At C:\temp\vDiagram01.ps1:42 char:13
+ $shpObj. <<<< Text = $item.name
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : PropertyNotFound
Adding Neverland Cluster
Exception calling "Drop" with "3" argument(s): "
An exception occurred."
At C:\temp\vDiagram01.ps1:40 char:27
+ $shpObj = $pagObj.Drop <<<< ($mastObj, $x, $y)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Property 'Text' cannot be found on this object; make sure it exists and is sett
able.
At C:\temp\vDiagram01.ps1:42 char:13
+ $shpObj. <<<< Text = $item.name
+ CategoryInfo : InvalidOperation: (Text:String) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:30 char:67
+ $connectBegin = $shpConn.CellsU("BeginX").GlueTo($firstObj.CellsU <<<< ("
PinX"))
+ CategoryInfo : InvalidOperation: (CellsU:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\temp\vDiagram01.ps1:33 char:64
+ $connectEnd = $shpConn.CellsU("EndX").GlueTo($secondObj.CellsU <<<< ("Pin
X"))
+ CategoryInfo : InvalidOperation: (CellsU:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : InvokeMethodOnNull
Any thoughts?
This is great, however when I run it, it doesn’t add the machine names. I’m getting the following error…
Exception setting “Text”: Cannot convert the “SERVER NAME” value of type “VirtualMachineImpl” to type “string”.
Any ideas?
Visio 2013
WOW! Not only is this script worthy of an innovation award, it looks extremely familiar to me. Great share! I’m sure others can use it for extreme gainz within their company.
Innovation! Award winning innovation! Nice.
Make sure you add it to the GitHub repo, sounds like great enhancements! https://github.com/alanrenouf/VisioPowerShell
All,
I’m currently working on adding an additional functionality to the script. Specifically, eliminating the ESX host within the ESX cluster visio plotting due to the diagram being inconsistent if vmotion via DRS is enabled for the cluster. I have already modified the script to connect the VM guest directly to ESX cluster. I’m also adding additional information to be added for each VM guest (OS version, IP address (Nic1), MemoryGB, NumCPU) as well as updating the stencil objects being used.
More Information to follow, so stay tuned
Best,
Blairzy
VCP6-DCV
MCSE 2012 Server Infrastructure
MCSA: Windows Server 2012
MCSA: Windows Sever 2008
Works fine with PowerCLI 6.0 R3 with Visio 2013 with one minor tweak for VM names to be displayed in. Line 42: “$shpObj.Text = $item” needs to be updated to “$shpObj.Text = $item.name”
This Script runs fine but only produces a single object of the root vcenter, nothing else is displayed
How hard is it to add IP addresses to the diagram? I’m new at scripting.
how to draw Visio for Datastore?
Brilliant Script! Thanks a million for saving many hours.Works fine with Visio 2010.
I tried this but get –
Index was outside the bounds of the array.
At D:\Documents\VMware\PowerCLI\vDiagram\vDiagram.ps1:42 char:5
+ $shpObj.Text = $item
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Any thoughts?
I was able to get this working with Visio 2013, on Windows 8.1 on a Vsphere 5.5 VC today! Once I installed VMware-PowerCLI-5.5.0-1295336, I had to ‘Set-ExecutionPolicy Unrestricted’ for Powershell to allow it to run.
Hi alan, Thanks for sharing, I followed the instructions by copying ‘My-VI-Shapes.vss‘ file to ‘My Documents\My Shapes’ folder. I ran the script, it ran successfully and it showed it saved the file with the name of my_vdiagram.vsd but i do not see any file in that path, I searched entire C drive with file name or *.vsd. There is none. I am wondering did it actually create something?
This script saves me at least 1 to 2 days each time I run it. Capturing the Virtual Infrastructure by hand is a non-starter! Thanks for a great piece of work!
This is a great script – however i’m having an issue where it wants to draw each cluster twice before it ends.
Any ideas.
Also i’ve modified it to produce a view of datastores.
Added:
$Storage = $stnObj.Masters.Item(“Folder”) under # Load a set of stencils and select one to drop
Then Added:
ForEach ($VMHost in (Get-Cluster $Cluster | Get-VMHost))
{
$Object1 = add-visioobject $HostObj $VMHost
connect-visioobject $CluVisObj $Object1
ForEach ($DataStore in (Get-vmhost $VMHost | Get-Datastore))
{
$x += 1.50
$object2 = add-visioobject $Storage $DataStore
Again i’m up against the issue where it wants to diagram everything twice.
Cheers,
Nathan.
sorry i know that thevesi is dead. What I mean is where is the updated vDiagram script now.
Sorry
I am looking for the updated script on thevesi.
I have PowerGUI and the power pack installed and would like to use the updates vDiagram script as mu vurrent visio is a litte crazy due to hundreds of VMs.
Works fine with Visio 2010.. For what its worth, i used x64 PowerCLI and x64 Visio2010
Pingback: Netapp Powershell & PowerCLI Scripts « NetApperos.com
agreed, not working w Visio 2010.
Not working with Visio 2010 errors out on the powershell prompt
Seems can’t running with Viso 2010 version
Will this script also work to display the same volumes information for vfilers? If so how do I modify this script to display this information.
thanks for awesome script
Pingback: Virtu-Al | Virtually everything is poshable
Sorry Imy, someone hacked my site last week and im only just restoring things fully now, hopefully it should be there now.
Hi the download is not working for me could you please email it to me?
thanks in advance.
Thanks
Imy
Would it be possible to populate each object with VM machine detail? like IP MAC, CPU count , RAM etc?
I’m saving the detail to an htm doc and publishing this for non VC users to see.
Thanks for everything
Maybe you could change the blog subject title vDiagram – Draw your VI with one script | Virtu-Al to something more better for your blog post you create. I loved the post however.
Mine asks for the ESX/Vcenter host, when I type it, Visio 2010 opens, but the diagram is blank?
brilliant stuff!
is there a possibility to save the output also as html?
Sorry for the stupit question but I’ll get always this error:
The term ‘.\vDiagram.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:15
+ .\vDiagram.ps1 <<<< -VIServer em1apvm001
+ CategoryInfo : ObjectNotFound: (.\vDiagram.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Thanks
Guido
Pingback: vSphere Documenters « Roshan Ratnayake – IT Architect
Pingback: Draw your VI environment with a script « a CraZy PeNguIn
Thanks Al!!
@Pushpal
I have changed the download link as was having problems with some people unable to access it. should be ok now.
Al, dont see the zip file, how can i get it?
As a Newbie, I am always searching online for articles that can help me. Thank you!
@Vikash Kumar
Emailed. Hope it works ok
I am not able to download the zip file. Can some one plesae pass me?
Thanks,
Vikash
@Bill
Bill, you may want to check out Thevesi.org as they have taken this script and enhanced it beyond belief, check here for a video of it in use: http://www.virtu-al.net/uo-vmug/
How would this work in a large environment, say 110 ESX hosts and 1500 VMs? Would the resulting file be usable or printable? Maybe on a plotter?
Pingback: Beta: Vizioncore Virtualization EcoShell « ICT-Freak.nl
Josh,
That is true for the moment buy I happen to have a little inside knowledge and don’t worry, you will be a happy man soon 😉
Hello thanks for that however the power gui version seems to only work with visio 2007 and our desktop soe is office 2003.
Yeah this is easy enough and I was planning on a V2 of this script but….. If you check out what has been done in the PowerGUI Powerpack with this script and also look out on http://www.thevesi.org they will be adding this to there version (which is better than this one) in the near future.
Hope that helps.
Hello is there anyway you can get this script to populate visio with the vmsdetails such as memory cpu and os?
Pingback: Travel back in time with Veeam Reporter - Storage Informer
Pingback: VMware Infrastructure PowerPack 2.1.5 released « Poshoholic
Cameron, Thanks, neat trick, BTW I think you may need to invest in some knee pads by the looks of your blog !
Alan,
For the “My Shapes” path, try this instead:
$stnPath = $AppVisio.MyShapesPath
Thanks for the great script.
—
Cameron
Patrick, Thanks for your Translation 🙂
David, Can you send me a little detail about your envionment. Thanks
For all german Users out there:
Chage Line 61 to “Meine Shapes” instead of “My Shapes”
Errors out with:
Adding
Get-VMHost : The argument cannot be null or empty.
At C:\scripts\vDiagram.ps1:136 char:30
Any ideas?
Alan,
Nice work, especially given the always tough to find documentation for Visio. Can’t wait for version 2, maybe add a title to page?
gb
Can someone post instructions on how to wrap the VMs to a second line (ie. 50 VMs on one host makes a big long diagram)…
Joe,
Im so sorry, I knew I missed someone out of the credits, I have ammended the post to include a link to the great CommandBreak_ site. Thanks for all of Ben’s help.
Alan
Michael,
Sounds good, send the amendments over and I will put them in V2.
Alan
If 46 VMs on one host makes your diagram a little on the wide side, it is possible to wrap them onto additional rows.
The changes will take too long to describe here but it is possible.
Looks familiar http://www.commandbreak.com/2007/10/14/VisioPowershellAutomagic.aspx
Nice One.
One quick question, what version of Visio are you using ?
Rob P
Brilliant!
My current client has a bizarre policy of using very long VM names however for clones that they have produced for backup purposes. To get around that I have added the following:
1. A line beneath the $Savefile declaration:
[int]$maxtextlength = 15
2. A function in with the other functions:
function format-itemtext($item)
{
$itemtext = $item.Name
if($maxtextlength -lt [int]$itemtext.length)
{
$itemtext = $itemtext.substring(0,$maxtextlength) + “…”
}
return $itemtext
}
3. Modified one line in the function add-visioobject:
$shpObj.Text = format-itemtext($item)
The result is VM names truncated to 15 characters plus “…” to indicate that they are not the full name.
Awesome stuff Alan,
Changed Line 93 from:
ForEach ($VM in (Get-vmhost $VMHost | get-vm))
To:
ForEach ($VM in (Get-vmhost $VMHost | get-vm -NoRecursion))
This fixes all VMs showing up under all hosts. Also fixed some of the Visio shapes with font size, etc. Was easy since I made the originals! Awesome awesome stuff.
Thanks Chris, couldn’t have done it without your brilliant forum and help !
Hopefully others on your forum will see the power of using Visio and PowerShell together 🙂
Alan
Hi Al,
Glad to see you’ve got it working!
– Chris (aka Visio Guy)
Sweet ! This really saves some work. Thanks !