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-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
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
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.
I assume all the VMs have VMware Tools installed?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Would something like this work?
Note that it assumes that VMware Tools are installed and that a VM only has 1 vNIC.
$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
Yes they do.
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
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
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}}
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-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
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}}
}
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-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
That worked perfectly, thank you!