Home > Blogs > VMware PowerCLI Blog


InventorySnapshot – Automatic PowerCLI code

ISFadeAt VMware, our engineers work on lots of pet projects in their spare time, and are always looking to get feedback on their projects, recently we started a new area of the VMware Labs site to allow them to share these with you.  We call these flings !

Why flings?

A fling is a short-term thing, not a serious relationship but a fun one. Likewise, the tools that are offered in the flings area are intended to be played with and explored. None of them are guaranteed to become part of any future product offering and there is no support for them. They are, however, totally free for you to download and play around with them!

InventorySnapshot

Balaji Parimi

Works in the Ecosystem Engineering group.

Ravi Soundararajan

Works in the Performance group

A recent fling which has just been released by the above two engineers is called InventorySnapshot, this fling allows a user to "snapshot" a given vCenter inventory configuration and then reproduce it. The "inventory" includes the Datacenter folders, datacenters, clusters, resource pools, vApps, hierarchy, roles and permissions, configuration settings, and custom fields. In other words, if you have an inventory with a given set of hosts and VMs organized into a group of clusters, we can faithfully reproduce this environment, including the cluster settings and custom roles you may have defined.

As a simple example, suppose you have an inventory with one datacenter (DC A), one cluster (Cluster A), and two hosts (Host A and Host B). At a high level, the fling emits a PowerCLI script that, when executed, does the following:

  1. Creates Datacenter “DC A.”
  2. Creates cluster “Cluster A.”
  3. Adds host “Host A” to “Cluster A.”
  4. Adds host “Host B” to “Cluster A.”

Notice that this can be helpful for a variety of reasons. For example, suppose you’ve spent a lot of time creating a development vCenter environment, and now you wish to deploy it in production. Using this fling, you can snapshot your “dev” environment and then run it against the “production” vCenter server, saving you the task of laboriously adding each host, creating the proper clusters and resource pools, etc.

Watch the following video to learn more about the power of this fling or head over to the InventorySnapshot page for more information.

This entry was posted in Advanced, vCenter on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Line Manager at VMware focusing on API's, SDK's and CLI's, He is responsible for providing the architects and operators of private and public cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI a book author and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

7 thoughts on “InventorySnapshot – Automatic PowerCLI code

  1. D K Lee

    This could make a vCenter upgrade / DB change much easier to accomplish.

    Reply
  2. Djamel

    Thank you,
    Does it work when Distributed Switch objects exist?
    Thank you

    Reply
  3. Ravi

    It should work with Distributed Switch objects. The caveat is that we’ve only tested it with VMware Distributed Virtual Switches, and not with Cisco or other virtual switches.
    Does that answer your question?

    Reply
  4. Vinod Sikka

    Hi, While running the tool, when it generates inventory, I do not see “commit Changes” button on third tab which is “inventory tree” which allows to select hosts on your choice for restoration rather taking all inventory. please help!

    Reply
  5. Cyril

    Hi there, thank you for this wonderful script. I’m going to rebuild our Vcenters and I have a couple of questions:
    1) I had to install Java on the original Vcenter to run your script, do I have to install jave before running the modified script on the new Vcenter or is it purely Powershell script?
    2) To restore my Vcenter, do I need to run Powercli 32 bits or 64 bits? I have installed V 5.5 of PowerCli and I know that some commandlets weren’t yet implemented in x64 bits. So which one do I use?

    Thanks!

    Reply
    1. Cyril

      Unfortunately the script doesn’t work in my environment. When I try to use the createinventory-passwordmodified.ps1 it goes through a few errors and nothing gets created.

      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4502 char:70
      + $cfView.setField($dsView.MoRef, $cfdHt.get_item(“NB_LAST_BACKUP”), “”Thu Apr 04 …
      + ~
      Missing ‘)’ in method call.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4502 char:70
      + $cfView.setField($dsView.MoRef, $cfdHt.get_item(“NB_LAST_BACKUP”), “”Thu Apr 04 …
      + ~~~
      Unexpected token ‘Thu’ in expression or statement.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4503 char:2
      + ,cg-backup,Copy_of_StandardVM_Test_Alertus””)
      + ~
      Missing expression after unary operator ‘,’.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4503 char:2
      + ,cg-backup,Copy_of_StandardVM_Test_Alertus””)
      + ~~~~~~~~~
      Unexpected token ‘cg-backup’ in expression or statement.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4503 char:11
      + ,cg-backup,Copy_of_StandardVM_Test_Alertus””)
      + ~
      Missing argument in parameter list.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4503 char:45
      + ,cg-backup,Copy_of_StandardVM_Test_Alertus””)
      + ~
      Unexpected token ‘)’ in expression or statement.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4518 char:70
      + $cfView.setField($dsView.MoRef, $cfdHt.get_item(“NB_LAST_BACKUP”), “”Mon Sep 15 …
      + ~
      Missing ‘)’ in method call.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4518 char:70
      + $cfView.setField($dsView.MoRef, $cfdHt.get_item(“NB_LAST_BACKUP”), “”Mon Sep 15 …
      + ~~~
      Unexpected token ‘Mon’ in expression or statement.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4519 char:2
      + ,cg-backup,CiscoAppliances””)
      + ~
      Missing expression after unary operator ‘,’.
      At C:\Inventory\data\2\createInventory-PasswordModified.ps1:4519 char:2
      + ,cg-backup,CiscoAppliances””)
      + ~~~~~~~~~
      Unexpected token ‘cg-backup’ in expression or statement.
      Not all parse errors were reported. Correct the reported errors and try again.
      + CategoryInfo : ParserError: (:) [], ParseException
      + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

      Reply
  6. Cyril

    Never mind, the script worked after I removed comments on VMs. Thanks!

    Reply

Leave a Reply

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

*