We are moving physical hardware from one datacenter to another. I have a list of affected vlans from the source datacenter. One of my goals is to see if there is a VLAN conflict (ie: does the source VLAN id exist at the destination datacenter and is used for a different Portgroup/subnet?).
1. What are the affected VMs along with various information regarding the VMs?
2. Am I better off simply using RVTools - vPort tab information and Excel formulas?
My SIDC_vlans_list.txt is simple (SIDC = datacenter). No header in file, just a list of vlans.File attached.
I was helped with a similar request and I modified the code to do similar
$vlanTab = @{}
Get-VM -PipelineVariable vm | Get-VirtualPortGroup |
ForEach-Object -Process {
$vlanTab.Add($_.VLanID, $vm)
}
Get-Content -Path .\SIDC_vlans_list.txt |
ForEach-Object -Process {
$vm = $vlanTab[$_]
$_ | Select @{N = 'VM'; E = {$vm.Name}},
@{N = 'IP'; E = {$vm.Guest.IPAddress[0]}},
@{N = 'Id'; E = {$vm.Id}},
@{N = 'Cluster'; E = {(Get-Cluster -VM $vm).Name}},
@{N = 'vlan'; E = {$_}},
@{N = 'vCenter'; E = {([uri]$vm.ExtensionData.Client.ServiceUrl).Host}}
}
I want to add the datastore(s), vmhost, and power state the VM is using along with one IP per column if the VM has multiple IPs (without the fe80::250:56f* Sample IP - 64.59.191.230|2001:4e8:0:4019::53:17|fe80::250:56ff:feb8:596| - I don't want the bolded that shows for nearly every IP. )
When I connected to one vcenter and ran the code I got the following:
I feel like I'm so close, yet so far away. Ideally, I want to be connected to all my vcenters to run this ( connect-viserver (get-content <name>.txt) ).
Thank you in advance.
It looks as if you have the same VLanId on multiple portgroups.
And the key into a hash table needs to be unique.
You can expand the key to make it unique.
For example you could combine the VlanId with the PortgroupName
Get-VM -PipelineVariable vm | Get-VirtualPortGroup |
ForEach-Object -Process {
$key = "$($_.Name)-$($_.VlanId)"
$vlanTab.Add($key, $vm)
}
The drawback is that you now have decompose the key to get the VlanId back.
And the 2nd part of the script also assumes that each portgroup has a unique VlanId.
You will have to rethink that part as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It looks as if you have the same VLanId on multiple portgroups.
And the key into a hash table needs to be unique.
You can expand the key to make it unique.
For example you could combine the VlanId with the PortgroupName
Get-VM -PipelineVariable vm | Get-VirtualPortGroup |
ForEach-Object -Process {
$key = "$($_.Name)-$($_.VlanId)"
$vlanTab.Add($key, $vm)
}
The drawback is that you now have decompose the key to get the VlanId back.
And the 2nd part of the script also assumes that each portgroup has a unique VlanId.
You will have to rethink that part as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Looks like I'd be best off to run the appropriate vPort portion of RVTools and use Excel formulas given our environment of multi-portgroups with the same vlan tag. As always, your advice is appreciated LucD .