registerVMX.pl (.vmx and .vmtx)

Version 1

    The motivation for this script actually came from a great PowerCLI script written by LucD which I read about in his recent blog post titled: Raiders of the Lost VMX in which users were looking for a way to locate all VM .vmx files within a datastore and register them to vCenter. Luc's script allows you to execute on either vCenter or individual ESX(i) host and allows you to specify specific entities to register such as a datacenter, cluster, or range of datastore(s)

     

    This script does exactly that of Luc's script including the ability to specify whether or not you want to also register templates (.vmtx). The one difference between this script and Lucs is this will actually capture all the host(s) that can mount to the datastore and randomly select a host to register set of VMs versus using the first host found to sort of load balance, if you're registering on a DRS enabled cluster, DRS will figure out the optimal placement upon power up. Luc's script is definitely shorter and probably more readable

     

    Requirements:

    vCenter 2.5 or vCenter 4.0

    ESX(i) 3.5 or 4.0

    vMA 4.0 or vCLI 4.0

     

    Sample Execution:

     

    Register all VMs under specific Datacenter:

    [vi-admin@scofield ~]$ ./registerVMX.pl --server reflex.primp-industries.com --datacenter "Primp-Test"
    
    Registering VM: vm-12 on Host: esx-60.primp-industries.com from Datastore: esx-60-local-storage-1 ...
            Sucessfully registered VM: vm-12!
    
    Registering VM: vm-2 on Host: esx-40.primp-industries.com from Datastore: LUN-007 ...
            Sucessfully registered VM: vm-2!
    
    Registering VM: vm-5 on Host: esx-60.primp-industries.com from Datastore: LUN-007 ...
            Sucessfully registered VM: vm-5!
    
    Registering VM: vm-6 on Host: esx-40.primp-industries.com from Datastore: LUN-007 ...
            Sucessfully registered VM: vm-6!
    
    Registering VM: vm-7 on Host: esx-20.primp-industries.com from Datastore: LUN-007 ...
            Sucessfully registered VM: vm-7!
    
    Registering VM: vm-1 on Host: esx-20.primp-industries.com from Datastore: esx-30-local-storage-1 ...
            Sucessfully registered VM: vm-1!
    
    Registering VM: vm-3 on Host: esx-40.primp-industries.com from Datastore: esx-40-local-storage-1 ...
            Sucessfully registered VM: vm-3!
    
    Registering VM: vm-4 on Host: esx-40.primp-industries.com from Datastore: esx-40-local-storage-1 ...
            Sucessfully registered VM: vm-4!
    

     

    Register all VM and VM Templates under specific Cluster

    [vi-admin@scofield ~]$ ./registerVMX.pl --server reflex.primp-industries.com --cluster "Primp-R&D" --findtemplates 1
    Registering VM: vm-1 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-1!
    
    Registering VM: vm-2 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-2!
    
    Registering VM: vm-3 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-3!
    
    Registering VM: vm-4 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-4!
    
    Registering VM Template: vm-template-1 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM Template: vm-template-1!
    
    Registering VM Template: vm-template-2 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM Template: vm-template-2!
    

     

    Register all VMs on a specific ESX(i) host

    [vi-admin@scofield ~]$ ./registerVMX.pl --server esxi35u4.primp-industries.com
    
    Registering VM: vm-1 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-1!
    
    Registering VM: vm-2 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-2!
    
    Registering VM: vm-3 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-3!
    
    Registering VM: vm-4 on Host: esxi35u4.primp-industries.com from Datastore: datastore1 ...
            Sucessfully registered VM: vm-4!
    

     

    Note: To search specific datastore just pass in the --datastore param with list of datastores to search seperated by commas:

     

    --datastore "ds1,ds2,ds3,ds4"