5 Replies Latest reply on Jun 16, 2011 6:35 AM by LucD

    unregistered template

    vcpguy Expert





      I need to find a script that will scan all my datastores for un-register tempaltes.



      Any ideas?






        • 1. Re: unregistered template
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          A template is in practice the same as a virtual machine with a few differences.

          The config file is not a .VMX but a .VMTX file and the VirtualMachine object contains a flag, called Template, which indicates if it concerns a virtual machine or a template.


          So I took one of my "find unregistered VMX files" scripts and with a few adaptations it now should be able to find unregistered templates.

          • 2. Re: unregistered template
            kleofas2 Novice

            Hi LucD


            Could this script be easily modified to find and register these templates?




            • 3. Re: unregistered template
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              The script in my Raiders of the Lost VMX post does exactly that.

              • 4. Re: unregistered template
                kleofas2 Novice

                Thanks LucD


                Great script - helped me a lot in restoring my templates from the datastore.

                We have them more than 100 so registering them manually could take an infinity.


                One thing - If I can suggest.

                When registering the vCenter firstly registers full name of the VM including datastore ID etc. like:



                If you have many templates with long, similar name and different ending - then vCenter throws many error messages.



                In fact - first and second machines were different and differed with just ending. After a while the long format was replaced by the shorter one (without datastore ID).


                I solved this problem by adding "sleep 30" after the line 95:

                $taskMoRef =$tgtfolder.GetType().GetMethod("RegisterVM_Task").Invoke($tgtfolder, $params)


                It caused that each registration was 30 seconds longer but the script didn't generate so much errors and don't have to be executed multiple times.

                Maybe the method is not elegant :-) I'm not a powerCLI expert, but it works.

                • 5. Re: unregistered template
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  That's an interesting discovery you made.

                  I suspect this caused by the way the RegisterVM_Task works internally.

                  I'l see if I can come up with a bypass.