6 Replies Latest reply on Jul 6, 2011 11:40 AM by DZ1

    Virtual machine custom value information removed

    DZ1 Hot Shot

      I am having a major problem; we use custom annotations to find out which users are assigned VM guests.  Recently we have had that information completely disappear from vSphere.  I am not sure what is happening.  There isn't anyone manually removing the information, and we have not performed any major updates or changes to our environment.

       

      We are using:

       

      vCenter Server 4.1.0

      ESXi 4.1.0

      HP BL460c G1

       

      This has happened at least 3 times; we first that that removing hosts from vCenter and adding them back caused the problem, however; the last time that it happened, we had not removed anything.

        • 1. Re: Virtual machine custom value information removed
          kjb007 Guru

          Have you performed any work on the vcenter db?  Restore/recovery?  Revert to snapshot?

           

          -KjB

          • 2. Re: Virtual machine custom value information removed
            DZ1 Hot Shot

            Thanks for the reply, we have not performed any work on the database and people do run individual snapshots on machines, but this has affected 20+ machines.  I would think that a snapshot would not affect the annotation.  We did have a VM report script that ran, and here it is.  I removed certain information from the script before posting; the script runs fine and it does not appear to erase data.

             

            I know some powershell, so I can understand what the script is doing generally, but someone else wrote it, and one portion is from the "Who created that VM" script that was posted before.

             

            I had someone else look at it and it appears to be working just fine.  I actually ran the script again (after the erased data) and it did not remove any data.

             

            # This IF codeblock will load the VMware PowerShell extensions
            # if they are not found to be loaded already
            if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
            {
                Add-PsSnapin VMware.VimAutomation.Core
            }

             

             

             

             

             

            function Get-VMReport($VMname) {
                # create a new object to fill with the information for the report
                $thisVMReportItem = New-Object PSObject
                $currentVM = Get-VM $VMname

             

                # create a property "Name" and populate with the Virtual Machine's name
                $thisVMReportItem | Add-Member -MemberType NoteProperty -Name "Name" -Value $currentVM.Name
                $thisVMReportItem | Add-Member -MemberType NoteProperty -Name "OSFullName" -Value $currentVM.Guest.OSFullName
               
               
                if ($currentVM.guest.ipaddress.count -gt 0)
                {
                    # get the first reported assigned IP address and add to the report information
                    $thisVMReportItem | Add-Member -MemberType NoteProperty -Name "IPAddress" -Value $currentVM.Guest.IPAddress[0].toString()
                }
                else
                {
                    # if there is no IP address information found, populate IPAddress with "unknown"
                    $thisVMReportItem | Add-Member -MemberType NoteProperty -Name "IPAddress" -Value "unknown"
                }
               
                # Retrieve the list of "Annotations" on each VM, loop through them

             

                $Annotations = $currentVM | Get-Annotation
                ForEach ($Annotation in $Annotations)
                {   
                    # if this specific Annotation is labelled "Assignee", add the value of that Annotation
                    # to the report information
                    if ($Annotation.Name -eq "Assignee")
                    {
                        $thisVMReportItem | Add-Member -MemberType NoteProperty -Name "Assignee" -Value $Annotation.Value
                    }
                    if ($Annotation.Name -eq "Z Version")
                    {
                        $thisVMReportItem | Add-Member -MemberType NoteProperty -Name "Z Version" -Value $Annotation.Value
                    }
                 
                }
               
                return $thisVMReportItem

            }

             

             

             

             

             

             

             


            # creates an empty collection object that will be filled with the information regarding each VM
            $AllVMReport = @()

             

            # Get a list of all of the VMs managed by the vCenter instance
            # sorted by name, then feed that list of objects into the ForEach
            # loop

             

            # connect to a VMware server (vCenter or ESX hypervisor host)

             

            connect-viserver
            $vms4report = @()
            get-vm -location  | foreach-object {$vms4report += $_}
            get-vm -location  | foreach-object {$vms4report += $_}
            get-vm -location  | foreach-object {$vms4report += $_}
            foreach ($vm in $vms4report)
            {
                $AllVMReport += Get-VMReport($vm.Name)
            }
            disconnect-viserver  -force -Confirm:$False

             

            connect-viserver
            $vms4report = @()
            get-vm -location 1 | foreach-object {$vms4report += $_}
            get-vm -location 2 | foreach-object {$vms4report += $_}
            get-vm -location 3 | foreach-object {$vms4report += $_}
            foreach ($vm in $vms4report)
            {
                $AllVMReport += Get-VMReport($vm.Name)
            }
            disconnect-viserver -force -Confirm:$False

             


            # HTML header information to provide formatting to the HTML output
            $htmlformatting = "<style>"
            $htmlformatting = $htmlformatting + "BODY{background-color:white;}"
            $htmlformatting = $htmlformatting + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
            $htmlformatting = $htmlformatting + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
            $htmlformatting = $htmlformatting + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
            $htmlformatting = $htmlformatting + "</style>"
            $today = get-date
             
            $AllVMReport | select Name,Assignee,IPAddress,ZVersion | sort-object -property Name | ConvertTo-HTML Name,Assignee,IPAddress,ZVersion -head $htmlformatting -body "<H2>VM Information collected on $today</H2>" | Set-Content C:\Scripts\report.html

            • 3. Re: Virtual machine custom value information removed
              continuum Guru
              Community WarriorsvExpertUser Moderators

              > I would think that a snapshot would not affect the annotation.

               

              annotations are stored in the vmx-file - so I would expect that going back to a snapshot would also change the annotations

              • 4. Re: Virtual machine custom value information removed
                DZ1 Hot Shot

                I do see where the "Notes:" are in the .vmx file, I made some changes, looked at the file and saw it there.  In vCenter under Custom Attributes, there was a custom attribute made with the Name Assignee, and Type Virtual Machine, the .vmx file does not have those notes, so it would appear that a snapshot rollback would not affect it.

                 

                Also, we didn't revert to any snapshots so we can rule that out, but it's good to know that the notes are kept in the .vmx file.  I did not know that, thanks.

                • 5. Re: Virtual machine custom value information removed
                  kjb007 Guru

                  This script is not setting anything in the actual vm object itself, so that appears fine.

                   

                  What about some automated snapshot tools, backup software?  Do you use a management software that may be making changes here?

                   

                  -KjB

                  • 6. Re: Virtual machine custom value information removed
                    DZ1 Hot Shot

                    Well, our environment has not had any data go missing again, and we are still running the script.  This will remain a mystery, but thanks for the help.