19
Jan/09
16

Check VMware Configuration with Powershell

I have promised you I would post this script, so here it is!

This Powershell script generates an overview of any items that are not available to every ESX server in a VMware cluster. These items might prevent your vm’s being vmotioned by DRS or restarted by HA. Pretty serious business, I’d say!

The items involved are:
1. datastores
2. LUNs (important when using Raw Device Mappings)
3. port groups

The output is a nicely formatted HTML page showing not only which items are misconfigured, but also where the are available and where they are absent.

Here’s an example:
Compare Screenshot

And here’s the script:
Compare-Clusters (Rename to .ps1)

Enjoy!
Hugo

  • Share/Bookmark

Related posts:

  1. Set VMware Snapshot Location with Powershell
  2. Examine VMware CPU Ready Times with Powershell
  3. Create a vSwitch Port Overview with Powershell

Comments (16) Trackbacks (3)
  1. Alan Renouf
    14:03 on January 19th, 2009

    That is one usefull script, nice one.

  2. Sven Huisman
    15:47 on January 19th, 2009

    Very nice! Bookmarked, downloaded and printed! Thanks.

  3. Jay Rogers
    15:09 on January 22nd, 2009

    I had problems running your script:

    PS C:\iso\powershell> ./compare-clusters.ps1
    There were one or more problems with the server certificate:

    * A certification chain processed correctly, but terminated in a root certificate which isn’t trust
    d by the trust provider.

    * A required certificate is not within its validity period.

    * The certificate’s CN name does not match the passed value.

    Get-View : The argument cannot be null or empty.
    At C:\iso\powershell\compare-clusters.ps1:23 char:36
    + $VMHostViews = $VMHosts | Get-View <<<< | Sort Name
    Get-Datastore : The argument cannot be null or empty.
    At C:\iso\powershell\compare-clusters.ps1:26 char:37
    + $Datastores = Get-Datastore -VMHost <<<< $VMHosts
    Get-Datastore : The argument cannot be null or empty.
    At C:\iso\powershell\compare-clusters.ps1:27 char:82
    + $DSdiffs = $VMHosts | ForEach {Compare-Object $Datastores (Get-Datastore -VMHost <<<< $_) -S
    yncWindow 1000} | ForEach {$_.InputObject} | Sort Name | Select Name -Unique
    Compare-Object : Cannot bind argument to parameter ‘ReferenceObject’ because it is null.
    At C:\iso\powershell\compare-clusters.ps1:48 char:30
    + $LUNdiffs += Compare-Object <<<< $LUNs $HostLUNs -SyncWindow 1000 | ForEach {$_.InputObj
    ect}
    Get-VirtualPortGroup : The argument cannot be null or empty.
    At C:\iso\powershell\compare-clusters.ps1:73 char:44
    + $PortGroups = Get-VirtualPortGroup -VMHost <<<< $VMHosts | ForEach {$_.Name} | Select -Uniqu
    e
    Get-VirtualPortGroup : The argument cannot be null or empty.
    At C:\iso\powershell\compare-clusters.ps1:77 char:42
    + $HostPGs = Get-VirtualPortGroup -VMHost <<<< $VMHost | ForEach {$_.Name} | Select -Uniqu
    e
    Compare-Object : Cannot bind argument to parameter ‘ReferenceObject’ because it is null.
    At C:\iso\powershell\compare-clusters.ps1:78 char:29
    + $PGdiffs += Compare-Object <<<< $PortGroups $HostPGs -SyncWindow 1000 | ForEach {$_.Inpu
    tObject}

    • admin
      15:21 on January 22nd, 2009

      The first error says that Get-View did not get any arguments. So there are two possible causes:
      1) Get-View does not support input from pipeline. This is only the case for the beta release of the VI Toolkit. Make suer you use the v1.0.
      2) The $VMHosts variable is empty, which would mean filling it somehow went wrong. Try dot-sourcing the script (start powershell interactively and run “. c:\iso\compare-clusters.ps1″ (without the quotes). Then take a look ate the variable $VMHosts if it contains anything.

      Good luck,
      Hugo

  4. Daniel Hernandez
    18:47 on January 27th, 2009

    Hey thanks for the great script. I also get a bunch errors similar to the one posted above. For the most part the script seems to run and produce a report its been very helpful in identifying invalid configurations.

    As for possible debugging information that may help with the errors.

    VC is 2.5 Update 3 on Win2k3 Server
    Host are mostly 3.01
    Toolkit Version is 1.0 build 113525

    Am not sure if your open to feed back to continue to improve the script or if you released it to the community and for them to have at it.

    If so here is my feedback.

    Since its a cluster audit it would be nice not to see the local disk. Since I’ve seen most environments local label vary from host to host usually something along the lines with the hostname this usually helps to ensure that nobody puts a VM on the Local host.

    Also I glance thru the script and I’m not sure are you checking for VLAN tags. Are you ? I’ve seen many issues because somebody fat fingered a VLAN tag. So a VM will move but not respond to any pings. Or even the VMotion port group wont move the VM because of the VLAN tag.

    Thanks again

    • admin
      22:21 on January 27th, 2009

      Hi Daniel, thank you for taking the time to post your comment. I read every comment on my site and try to improve my scripts or help out in other ways. Keep watching my site and you might see an improved version of the script some time soon. Thanks again for your comments!
      Hugo

  5. Roderick
    10:28 on January 28th, 2009

    How do I get rid of this annoying output when I run the powershell scripts?

    There were one or more problems with the server certificate:

    * A certification chain processed correctly, but terminated in a root certificat
    e which isn’t trusted by the trust provider.

    • admin
      10:49 on January 28th, 2009

      You can import the certificate to get rid of the first message, but the second one will remain as your server will most likely not be called ‘vmware’. Might work to create a dns alias for it, but that’s not very nice. Maybe you can find out a way to generate a new certificate with the proper server name in it. If anybody finds a way before I do, let me know.
      Hugo

  6. Larry
    15:33 on February 3rd, 2009

    Thanks for lots of great scripts. Looking for VCB ones but liked what I found anyway. My script works some time but other times the snapshot times out. Wanted your clear connection script to see if that was my issue, wasn’t. Your list disks script will help also.

  7. Roderick
    16:54 on February 5th, 2009

    This is probably an open door, but how do I import a certificate?

  8. Paul
    11:14 on February 12th, 2009

    Hi Hugo,

    I was trying to do exactly as Daniel requested and managed to fudge something together. Would appreciate it if you would take the time to have a look and see how it could be improved as i think the method I came up with to compare VLANS works but is a little convoluted.

    let me know if you have the time or inclination to take a look and i’ll post the script.

  9. Hugo
    11:55 on February 12th, 2009

    @Paul
    Hi Paul,
    Sure I’d like to check what you did. Drop me an email at: contact at peetersonline nl
    Hugo

  10. Duncan
    9:03 on February 16th, 2009

    Just ran this script and it works fine but:
    - you might want to filter the local luns (vmhba0:0:0) cause they usually have a different name on every single host in a cluster
    - the script throws an error when a cluster doesn’t contain hosts

  11. Nick
    18:32 on May 11th, 2009

    I was wondering if Paul had a workable solution or addition for auditing the port group VLANs. I love the script above but really need to audit the por group VLANs as well.

  12. Alan
    17:59 on June 24th, 2009

    agree with Duncan, GREAT script but is there an easy way to filter out local luns?

  13. level67
    4:20 on October 9th, 2009

    Hi Guys,

    Got the same issue, its reporting my local drives as datastores and reporting a mismatch on the clusters.

    Any chance of looking into this? Great work otherwise… love it!

Leave a comment