VMware Cloud Community
CEHaas
Contributor
Contributor
Jump to solution

Exporting VM Information

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 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
CEHaas
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I assume all the VMs have VMware Tools installed?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

CEHaas
Contributor
Contributor
Jump to solution

Yes they do.

Reply
0 Kudos
CEHaas
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
CEHaas
Contributor
Contributor
Jump to solution

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}}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

CEHaas
Contributor
Contributor
Jump to solution

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}}

}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
CEHaas
Contributor
Contributor
Jump to solution

That worked perfectly, thank you!

Reply
0 Kudos