1 2 Previous Next 15 Replies Latest reply on Oct 7, 2020 3:12 AM by LucD

    Replace Bios.UUID after clone (copy uuid to clone)

    OBTMOM Novice

      Good evening,

      we do run a test lab with some bigip appliances. As we play around with them and usually mess them up i wanted to create a clone to have a full backup of a clean appliance.

      i figured out when i copy the bios.uuid i will not loose the activated license and so i do not need to bother the vendor again and again.

       

      I am stuck in my scheduled task with the replacement. The tasks run shutdown the vm and take the clone.

      I have to run these actions in jobs don't ask me why. I could figure out why the "pure" commands do not work.

       

      So here is the piece where i am stuck... And i would love if someone could enlighten me to get this to run.

      I tagged the machines so the bios.uuid will not get replaced on other machines. Having the vendor details of the vm would be much cooler and i might open another post about this.

       

      So i get the uuid from the master vm

      # Get BIOS UUID

      $uuid = Get-VM $vmname | %{(Get-View $_.Id).config.uuid}

      And geht the Tag of the vm

      # Get Tag of Virtual Machine (if assigned)

      $tag = Get-VM $vmname | Get-TagAssignment | select Tag

       

      $vmname is the master

      $firstbackupname is the name of the clone

       

      And here is the code which should replace the uuid on the vm ($firstbackupname)

       

      if ($tag -match "F5") {

                             LogWrite ""

                             LogWrite "Task Backup - F5 Tag assigned. Changing UUID"

                             Start-Job -ScriptBlock {

                                                      $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

                                                      $spec.uuid = $uuid

                                                      $firstbackupname.Extensiondata.ReconfigVM_Task($spec)

                                                     }

                             Get-Job | Wait-Job

                             LogWrite "-OK-----------------> Changed UUID to $uuid"

                            }

       

      The scenario does shutdon the vm, wait for shutdown then take a clone and now it should copy the master uuid to the clone. Right after the vm gets a power on.

       

      I would be very happy if you coudl help me out here.

      thank you very much for any tip and help.

       

      best wishes armin

        • 1. Re: Replace Bios.UUID after clone (copy uuid to clone)
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          Do you remove the 'master' completely before trying to assign the UUID to the clone?

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Replace Bios.UUID after clone (copy uuid to clone)
            OBTMOM Novice

            Hi Luc,

             

            no the master will run until he is so misconfigured that we need to restore it to a clean state.

            We do keep it and a clone (fresh installed with base config) as a backup.

            And to keep the license activated the vm needs to have the same uuid.

            thanks!

            • 3. Re: Replace Bios.UUID after clone (copy uuid to clone)
              LucD Guru
              vExpertCommunity WarriorsUser Moderators

              I'm not sure that vCenter will allow VMs with the same UUID to co-exist

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Replace Bios.UUID after clone (copy uuid to clone)
                OBTMOM Novice

                Hi Luc,

                the backup stays offline and disconnected. If the master fails it will get deleted.

                And the clone will get the master.

                They will never run or being online at the same time.

                See it like a save copy of the master.

                thanks

                • 5. Re: Replace Bios.UUID after clone (copy uuid to clone)
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  But they are both present in the vCenter database

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Replace Bios.UUID after clone (copy uuid to clone)
                    OBTMOM Novice

                    Correct Luc.

                    I can replace the uuid with the command manually.

                    But would like to script it with the clone automation

                     

                    Manually works:

                    #

                    # Get BIOS UUID

                    $uuid = Get-VM $vmname | %{(Get-View $_.Id).config.uuid}

                    #

                    # replace UUID on backup

                    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

                    $spec.uuid = $uuid

                    $firstbackupname.Extensiondata.ReconfigVM_Task($spec)

                     

                    But in the scheduled job clone script it does fail.

                     

                     

                    if (Get-VM $vmname | Get-TagAssignment |where{$_.Tag -like “F5*”}) {

                                                                                        Get-VM $firstbackupname

                                                                                        $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

                                                                                        $spec.uuid = $uuid

                                                                                        $firstbackupname.Extensiondata.ReconfigVM_Task($spec)

                                                                                       }

                     

                    And i do not understand why it fails and runs manually in ISE editior but not with powershell in a scheduled task.

                    had this with other actions like clone or delete a vm too. So here i used jobs to run in. Maybe because it is a scheduled task.

                    • 7. Re: Replace Bios.UUID after clone (copy uuid to clone)
                      LucD Guru
                      Community WarriorsUser ModeratorsvExpert

                      Is there any error message when it fails?

                      You could check the vpxd log, eventually setting the log level temporarily to 'verbose', for additional information.

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: Replace Bios.UUID after clone (copy uuid to clone)
                        LucD Guru
                        User ModeratorsCommunity WarriorsvExpert

                        I did some further testing (in vSphere 7).
                        I was able to change the UUID on the cloned VM, irrespective if the source VM was powered on or not.

                         

                        The conclusion would be that the issue is in your scheduled job.

                        How did you create the scheduled job?

                        Under which account does it run?

                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 9. Re: Replace Bios.UUID after clone (copy uuid to clone)
                          OBTMOM Novice

                          Hi Luc,

                          thanks for your help.

                           

                          The account is a domain account which has local admin rights on the vcenter appliance. (All rights assigned)

                          About the job. This runs on a windows server and i use scheduled task.

                           

                          trigger task

                          Runs every hour, collect data from csv and triggers the action script.

                          # Script will  check if time and backup matches on CSV

                          # Then it does trigger all actions below

                          #

                          $csv | ForEach-Object {

                                                 if (($_.backup -match “yes”) -and ($hour -eq $_.time) -and ($_.days -match $today))

                                                  {

                                                     LogWrite ““

                               LogWrite “Time $hour o’clock  Basel Time”

                                                     LogWrite “Session collection details for each machine”

                                                     LogWrite “$_”

                                                     $job = Start-Job -Name $_.vmname -FilePath “c:\Scripts\vm_backups\actions\vm_backup_action.ps1” -ArgumentList $_.vmname,$_.vmbackupname,$_.shutdown,$_.retention_local,$_.retention_nas | Out-Null

                                                     Start-Job -ScriptBlock $job

                                                     Get-Job | Wait-Job

                                                  }

                                                }    

                           

                           

                          Action script uses data from csv (param) and connects to the vcenter via encrypted credentials.

                           

                          Strange is that i have to put every clone task into a job.

                          # Create backup job

                                                                  $job = New-VM -Name $secondbackupname -VM $firstbackupname -Datastore $freespace2 -Location $backupfolder -VMHost $freespace2esx -notes $date

                                                                  Start-Job -ScriptBlock $job

                                                                  Get-Job | Wait-Job                            

                                                                  Start-Sleep -Seconds 10

                          #

                          As soon i try to run the command without $job it does fail.

                          I did not found out why it fails but to complete i did then use jobs to run the action.

                           

                          So maybe i need to run the change UUID task as a job as well.

                          Need to try.

                          • 10. Re: Replace Bios.UUID after clone (copy uuid to clone)
                            OBTMOM Novice

                            Not sure how i should pack these commands into a job.

                            THe others are in one row. This looks like to need more.

                             

                                                   Start-Job -ScriptBlock {

                                                                            $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

                                                                            $spec.uuid = $uuid

                                                                            $firstbackupname.Extensiondata.ReconfigVM_Task($spec)

                                                                           }

                             

                            Idea:

                            $job =    {

                                            $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

                                            $spec.uuid = $uuid

                                           $firstbackupname.Extensiondata.ReconfigVM_Task($spec)

                                           }

                            Start-Job -ScriptBlock $job

                            Get-Job | Wait-Job

                             

                            Maybe this will succeed...

                            What do you think?

                            • 11. Re: Replace Bios.UUID after clone (copy uuid to clone)
                              LucD Guru
                              vExpertCommunity WarriorsUser Moderators

                              How does it fail when you don't run it as a job?
                              Any error messages?
                              Perhaps try adding a transcript (Start-Transcript/Stop-Transcript) and verbose mode ($VerbosePreference) to get more details.

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 12. Re: Replace Bios.UUID after clone (copy uuid to clone)
                                LucD Guru
                                User ModeratorsvExpertCommunity Warriors

                                That will work (with the Start-Job).
                                Just define a code block (curly braces) with multiple lines.

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                1 person found this helpful
                                • 13. Re: Replace Bios.UUID after clone (copy uuid to clone)
                                  OBTMOM Novice

                                  Hey Luc,

                                  i will try. Keep fingers crossed.

                                   

                                  Luc, thank you very much for your help!

                                  • 14. Re: Replace Bios.UUID after clone (copy uuid to clone)
                                    OBTMOM Novice

                                    This thing drives me mad....

                                     

                                    Since this morning when i try to run the script from ISE editor or powercli i receive an error...

                                    Variable of $uuid and $vmname is correct and gets listed when i call them.

                                     

                                    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

                                    $spec.uuid = $uuid

                                    $vmname.Extensiondata.ReconfigVM_Task($spec)

                                     

                                     

                                     

                                    You cannot call a method on a null-valued expression.

                                    At line:3 char:1

                                    + $vmname.Extensiondata.ReconfigVM_Task($spec)

                                    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                                        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

                                        + FullyQualifiedErrorId : InvokeMethodOnNull

                                     

                                    Any clue on what seems to be wrong?

                                    I compared the commands and all looks well....

                                     

                                    frustrating...

                                     

                                     

                                    Thanks!

                                    1 2 Previous Next