Virtu-Al.Net

Virtually everything is poshable

vDiagram – Draw your VI with one script

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:
  1. Download the zip file from the bottom of this page
  2. 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.
  3. 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



42 Responses to “vDiagram – Draw your VI with one script”

  • Anonymous says:

    Sweet ! This really saves some work. Thanks !

  • Visio Guy says:

    Hi Al,

    Glad to see you’ve got it working!

    - Chris (aka Visio Guy)

  • Virtu-Al says:

    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

  • Scott Herold says:

    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.

  • Michael Poore says:

    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.

  • Anonymous says:

    Nice One.

    One quick question, what version of Visio are you using ?

    Rob P

  • Michael Poore says:

    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.

  • Virtu-Al says:

    Michael,

    Sounds good, send the amendments over and I will put them in V2.

    Alan

  • Virtu-Al says:

    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

  • Stephen says:

    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)…

  • Anonymous says:

    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

  • David says:

    Errors out with:

    Adding
    Get-VMHost : The argument cannot be null or empty.
    At C:\scripts\vDiagram.ps1:136 char:30

    Any ideas?

  • Patrick says:

    For all german Users out there:

    Chage Line 61 to “Meine Shapes” instead of “My Shapes”

  • Virtu-Al says:

    Patrick, Thanks for your Translation :)

    David, Can you send me a little detail about your envionment. Thanks

  • Cameron says:

    Alan,
    For the “My Shapes” path, try this instead:

    $stnPath = $AppVisio.MyShapesPath

    Thanks for the great script.

    Cameron

  • Virtu-Al says:

    Cameron, Thanks, neat trick, BTW I think you may need to invest in some knee pads by the looks of your blog !

  • [...] that I’ve been working on.  The Visio scripts I’m referring to were largely inspired by Alan Renouf’s vDiagram script, although the Visio script I ended up with doesn’t look anything like the original.  I’m [...]

  • [...] of people have been building reporting tools on top of VI Toolkit, such as Alan Renouf

  • Hello is there anyway you can get this script to populate visio with the vmsdetails such as memory cpu and os?

  • Virtu-Al says:

    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.

  • Josh williams says:

    Hello thanks for that however the power gui version seems to only work with visio 2007 and our desktop soe is office 2003.

  • Virtu-Al says:

    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 ;)

  • [...] of the best features is based on a script from Alan Renouf (vdiagram) and it’s called Generate [...]

  • Bill says:

    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?

  • Virtu-Al says:

    @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/

  • Vikash Kumar says:

    I am not able to download the zip file. Can some one plesae pass me?

    Thanks,
    Vikash

  • Virtu-Al says:

    @Vikash Kumar
    Emailed. Hope it works ok

  • As a Newbie, I am always searching online for articles that can help me. Thank you!

  • Pushpal says:

    Al, dont see the zip file, how can i get it?

  • Virtu-Al says:

    @Pushpal
    I have changed the download link as was having problems with some people unable to access it. should be ok now.

  • Pushpal says:

    Thanks Al!!

  • [...] Check out the script and more info here [...]

  • [...] vDiagram - http://www.virtu-al.net/2009/01/26/vdiagram-draw-your-vi-with-one-script/ [...]

  • Guido says:

    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

  • Rene says:

    brilliant stuff!

    is there a possibility to save the output also as html?

  • Justin says:

    Mine asks for the ESX/Vcenter host, when I type it, Visio 2010 opens, but the diagram is blank?

  • 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.

  • Nathan says:

    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

  • Imy says:

    Hi the download is not working for me could you please email it to me?
    thanks in advance.

    Thanks
    Imy

  • Alan says:

    Sorry Imy, someone hacked my site last week and im only just restoring things fully now, hopefully it should be there now.

  • [...] that’s right, Kirk has taken my Visio script, torn it up, threw it out and come up with something completely [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>