12 Replies Latest reply on Sep 24, 2020 7:55 AM by CEHaas

    Exporting VM Information

    CEHaas Novice
      I'm woring on a rather complex situation.  I am using Veeam for planned failovers for subsets of VMs.  These VMs are all DHCP, with reservations; and no I cannot change that part of the design.  I'm trying to script exporting the VM name, IP address and MAc address information for the original and replica VM.  My goal is to merge the new MAC address, with the old IP address so that I can update the DHCP reservation so that when we failover I can make the changes.
        • 1. Re: Exporting VM Information
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          If I understand your question correctly, you want to create a report that contains information from the original and the failover VMs.
          You would need to explain how these VMs can be retrieved.

          Do they have a specific name, or tags or custom attributes?

          How can a script derive the failover VM's name from the original VMs name?

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Exporting VM Information
            CEHaas Novice

            Here is the logical VMware layout, both source and destination VMs are logically organized by folders.

            VC

            -Datacenter1

              -Cluster1

               -Folder1

                  -Folder2

                      -VM1

            -Datacenter2

              -Cluster1

               -Folder1

                  -Folder2

                        - VM1_replica

             

            I can handle the failover via Veaam and replacing the MAC addressin the the DHCP leases via Powershell.  My issue is pulling the VM name, and IP from the Source VM and merges the MAC address form the _replica VM, into a CSV that I can run the powershell script against.

            • 3. Re: Exporting VM Information
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              I assume all the VMs have VMware Tools installed?

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Exporting VM Information
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                Would something like this work?
                Note that it assumes that VMware Tools are installed and that a VM only has 1 vNIC.

                 

                $dcName = 'Datacenter1'

                $clusterName = 'Cluster1'

                 

                Get-Datacenter -Name $dcName | Get-Cluster -Name $clusterName |

                Get-VM -PipelineVariable vm |

                ForEach-Object -Process {

                    $vmReplica = Get-VM -Name "$($vm.Name)_replica"

                    $vm | Select Name,

                        @{N='IP';E={$vm.Guest.IPAddress}},

                        @{N='MAC Replica';E={(Get-NetworkAdapter -VM $vmReplica).MacAddress}}

                }

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                • 5. Re: Exporting VM Information
                  CEHaas Novice

                  Yes they do.

                  • 6. Re: Exporting VM Information
                    CEHaas Novice

                    That's a very good start, however the replicas exist in a separate datacenter, managed by the same virtual center server.  Furthermore, I will be moving them by  groups; these will exist in folders.

                    Datacenter

                         |-Cluster1

                              |-Folder

                                   |-Sub-folder1

                                        |-VM1

                                        |-VM2

                         |-Cluster2

                              |-Folder

                                   |-Sub-folder1

                                        |-VM1_replica

                                        |-VM2_replica

                    • 7. Re: Exporting VM Information
                      LucD Guru
                      Community WarriorsvExpertUser Moderators

                      Are you saying that the Get-VM with the -replica name does not find the VM?

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: Exporting VM Information
                        CEHaas Novice

                        I had to make a change to get it to work, since the _replicas exist in a separate cluster, code below.  Since I have over 4,500 VMs in the Cluster, I woul like to filter by VM name by the first 2 characters to reduce the output size.

                         

                         

                        Get-Datacenter -Name $dcName | #Get-Cluster -Name $clusterName |

                         

                         

                        Get-VM -PipelineVariable vm |

                         

                        ForEach-Object -Process {

                         

                         

                            $vmReplica = Get-VM -Name "$($vm.Name)_AS"

                         

                         

                            $vm | Select Name,

                         

                         

                                @{N='IP';E={$vm.Guest.IPAddress}},

                         

                         

                                @{N='MAC Replica';E={(Get-NetworkAdapter -VM $vmReplica).MacAddress}}

                        • 9. Re: Exporting VM Information
                          LucD Guru
                          vExpertUser ModeratorsCommunity Warriors

                          I'm not sure I understand why you had to remove the Get-CLuster part.

                          The replica is retrieved with it's DisplayName, nothing to do with a cluster.

                           

                          In any case, you can use the Name value on the Get-VM to filter on the 1st characters.

                          For example -Name "AB*"

                           

                          Get-Datacenter -Name $dcName |

                          Get-VM -Name "AB*" -PipelineVariable vm |

                          ForEach-Object -Process {

                              $vmReplica = Get-VM -Name "$($vm.Name)_AS"

                              $vm | Select Name,

                                  @{N='IP';E={$vm.Guest.IPAddress}},

                                  @{N='MAC Replica';E={(Get-NetworkAdapter -VM $vmReplica).MacAddress}}

                          }

                          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 10. Re: Exporting VM Information
                            CEHaas Novice

                            I have modified it to filter by VM name and that is working great, however I ned to dump it to CSV and am struggling to get the report variable placed in the correct location.  Also, since these VMs also have an IPV6 address, I would like to filter that address out.

                             

                            Get-Datacenter -Name $dcName |

                            Get-VM | Where {($_.Name -like "Prefix*")} -PipelineVariable vm |

                            ForEach-Object -Process {

                                $vmReplica = Get-VM -Name "$($vm.Name)_AS"

                                $vm | Select Name,

                                    @{N='IP';E={$vm.Guest.IPAddress}},

                                    @{N='MAC Replica';E={(Get-NetworkAdapter -VM $vmReplica).MacAddress}}

                            }

                            • 11. Re: Exporting VM Information
                              LucD Guru
                              vExpertUser ModeratorsCommunity Warriors

                              The PipelineVariable on the Where-Object will not work I'm afraid.

                              But you do the same with Name value.

                              This also filters out IPv6 addresses and export the result to a CSV file

                               

                              Get-Datacenter -Name $dcName |

                              Get-VM -Name "Prefix*" -PipelineVariable vm |

                              ForEach-Object -Process {

                                  $vmReplica = Get-VM -Name "$($vm.Name)_AS"

                                  $vm | Select Name,

                                      @{N='IP';E={($vm.Guest.IPAddress | where{$_ -notmatch ":"}) -join '|'}},

                                      @{N='MAC Replica';E={(Get-NetworkAdapter -VM $vmReplica).MacAddress}}

                              } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 12. Re: Exporting VM Information
                                CEHaas Novice

                                That worked perfectly, thank you!