Visio using PowerCLI generate your vCenter Network Diagram

Visio using PowerCLI generate your vCenter Network Diagram

Visio using PowerCLI

In this blog post, i would be showing you a cool way using which you can generate a network map of your entire vmware infrastructure, it basically involves using powercli in conjunction with visio api calls to automatically generate a network diagram of your virtual infrastructure.

The script below needs a connectivity to a vCenter server, once established it would iterate across all the clusters in your environment and generate a visio for it and save it to a predefined destination location.

You would need to download the VMware EUC Visio Stencils 2015.vss stencils and save it in your visio shapes library.

In my setup i saved it in the “My Shapes” location as shown below in the screen capture.

test

Also note the script was tested in Visio 2013 and it worked flawless in generating the visio file.

Let me show a sample of how the Final completed Visio generated look’s like.

Visio using PowerCLI.

Visio using PowerCLI

Next let me walk you through the script itself.

First and foremost, you need to connect to the vCenter environment using

Next part of the script explanation is highlighted in the comments itself, so lets see its inner working. You can save it and reuse the code as per your environment, feel free to modify and add more content as the possibilities for this logic is endless.

Once the script kicks off, you would be stunned to see it open visio on its own and generate a network map right in front of your eyes with zero manual effort 🙂

And the best part if that when you browse to your  visio save folder, you would be treated to something like this 🙂

test

I hope you found this blogpost on generating Visio using PowerCLI useful and hope it helps you out!

Please follow and like us:

Share this post

11 thoughts on “Visio using PowerCLI generate your vCenter Network Diagram

  1. When I try to run this against my ESX 6.0 cluster I’m getting the below errors.

    New-Object : Creating an instance of the COM component with CLSID
    {00021A20-0000-0000-C000-000000000046} from the IClassFactory failed due to
    the following error: 80004002 No such interface supported (Exception from
    HRESULT: 0x80004002 (E_NOINTERFACE)).
    At C:\Temp\vDiagram.ps1:43 char:13
    + $AppVisio = New-Object -ComObject Visio.Application
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [New-Object], InvalidCastExce
    tion
    + FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShel
    .Commands.NewObjectCommand

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:45 char:1
    + $DocObj = $docsObj.Add(“Basic Network Diagram.vst”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:49 char:1
    + $pagObj = $pagsObj.Item(1)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:53 char:1
    + $stnObj1 = $AppVisio.Documents.Add($stnPath + $shpFile1)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:54 char:1
    + $VirtualMachine = $stnobj1.Masters.item(“Virtual Machine (3D)”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:55 char:1
    + $VirtualAppliance = $stnobj1.Masters.item(“3D Virtual Appliance”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:56 char:1
    + $vSphere = $stnobj1.Masters.item(“vSphere”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:57 char:1
    + $Clusters = $stnobj1.Masters.item(“Clusters 2”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:58 char:1
    + $VMware_Host=$stnobj1.Masters.item(“VMware Host”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:59 char:1
    + $datastores=$stnobj1.Masters.item(“Disks 1”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Adding CLUSTER: Lab Cluster 1
    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:29 char:11
    + $shpObj = $pagObj.Drop($mastObj, $x, $y)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    The property ‘Text’ cannot be found on this object. Verify that the property
    exists and can be set.
    At C:\Temp\vDiagram.ps1:31 char:11
    + $shpObj.Text = $item
    + ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    Adding NODE: 192.168.199.100eSXIVersion: 6.0.0
    TotalMemory(GB): 7.91
    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:29 char:11
    + $shpObj = $pagObj.Drop($mastObj, $x, $y)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    The property ‘Text’ cannot be found on this object. Verify that the property
    exists and can be set.
    At C:\Temp\vDiagram.ps1:31 char:11
    + $shpObj.Text = $item
    + ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:17 char:5
    + $shpConn = $pagObj.Drop($pagObj.Application.ConnectorToolDataObject, 0,
    0)
    +
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:19 char:5
    + $connectBegin =
    $shpConn.CellsU(“BeginX”).GlueTo($firstObj.CellsU(“PinX”))
    +
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:21 char:5
    + $connectEnd = $shpConn.CellsU(“EndX”).GlueTo($secondObj.CellsU(“PinX”))
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:117 char:1
    + $pagObj.ResizeToFitContents()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\Temp\vDiagram.ps1:120 char:1
    + $DocObj.SaveAs(“C:\Temp\$cluster.vsd”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Reply
  2. I tried the script and eveything works except the datastore part, I am getting the following error
    “Get-Datastore : The input object cannot be bound to any parameters for the
    command either because the command does not take pipeline input or the input
    and its properties do not match any of the parameters that take pipeline
    input.At C:\Users\ADAPAP1\Downloads\vDiagram\vDiagram_Network.PS1:64 char:33
    + $allDs = Get-Cluster $cluster | Get-Datastore
    + ~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (CLDLV-001:PSObject) [Get-D
    atastore], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.
    Cmdlets.Commands.GetDatastore”

    I know that the Get-Datastore should work, however it is not working in this case, any suggestions??

    Reply
      1. I upgraded my powerCLI from 5.1 to 5.5 Release 1 and the issue still persists, I don’t think its the powerCLI version, I think its somehow the way the script is executing and not able to store the output of Get-Datastore into the variable which is causing this issue. were you able to execute this in your environment without any issues? I still get the same error with Get-Datastore and everything else executes fine in the visio diagram.

        Reply
        1. can you manually run only that command on the powercli console and see whats the output, you would need to break it line by line. also please upgrade to powercli v6.0 r3 its the latest

          Reply
  3. I’m getting the same errors as Pradeep. I have PowerCLI 5.5 Release1. Running ‘Get-Datastores’ on its own, works fine. Any follow ups on this one.

    Reply

Post Comment