Get-Datacenter "CG-SO" | Get-Cluster|Get-VMHost |Get-VirtualPortGroup tells me the virtualportgroups and vlans.
NPR--10.1.202.0_24 key-vim.host.PortGroup-NPR-... 202
NPR--10.1.201.0_24 key-vim.host.PortGroup-NPR-... 201
NPR--10.1.113.0_24 key-vim.host.PortGroup-NPR-... 113
NPR--10.1.106.0_24 key-vim.host.PortGroup-NPR-... 106
I can get host and vm counts with the following:
Get-Cluster | Select Name, @{N="Host Count"; E={($_ | Get-VMHost).Count}}, @{N="VM Count"; E={($_ | Get-VM).Count}}
How do I combine the two to get the following?
Cluster VirtualPortGroup Vlan VMhost Count VM Count
CG-SO-PRE-DMZ-WINDOWS NPR--10.1.106.0_24 106 3 50
I want to identify those virtual port groups no longer in use to evaluate if they need to be removed. We've had several vlans removed from our network infrastructure over the years.
Try something like this.
Get-Cluster -PipelineVariable cluster |
Get-VMHost |
Get-VirtualPortGroup |
Select @{N = 'Datacenter'; E = {$dc.Name}},
@{N = 'Cluster'; E = {$cluster.Name}},
Name, VlanId,
@{N = 'VMCount'; E = {($_ | Get-VM).Count}} |
Group-Object -Property Datacenter, Cluster, Name |
ForEach-Object -Process {
$_ | Select @{N = 'Datacenter'; E = {$_.Name.Split(',')[0].Trim(' ')}},
@{N = 'Cluster'; E = {$_.Name.Split(',')[1].Trim(' ')}},
@{N = 'Portgroup'; E = {$_.Name.Split(',')[2].Trim(' ')}},
@{N = 'VlanId'; E = {$_.Group[0].VlanId}},
@{N = 'VMHostCount'; E = {$_.Count}},
@{N = 'VMCount'; E = {($_.Group | Measure-Object -Property VMCount -Sum).Sum}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This appears 6 times and then I get exactly what I want for the first datacenter (CG-CO-SBODEVDC). I have to assume that the errors I'm getting is one error per datacenter.
Get-Cluster : 2/11/2019 4:06:43 PM Get-Cluster VMHost parameter: Could not find any of the objects specified by name.
At line:2 char:1
+ Get-Cluster -PipelineVariable cluster
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutom...VMHost[] VMHost:RuntimePropertyInfo) [Get-Cluster], ObnRecordProcessingFailedException
+ FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster
Datacenter | Cluster | Portgroup | VlanId | VMHostCount | VMCount |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | Management Network | 2500 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | vMotionB | 2511 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | vMotionA | 2511 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | NFS_172.28.4 | 3004 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | StorageB | 2510 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | StorageA | 2510 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | NPR--10.15.80.0_24 | 2080 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | NPR--10.15.190.0_23 | 3190 | 4 | 0 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | NPR--10.15.182.0_24 | 3182 | 4 | 1 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | SBO--10.15.184.0/22--NPR | 3184 | 4 | 176 |
CG-CO-SBODEVDC | CG-CO-SBODEV-ORADB | NFS_Direct_172.28.56 | 3056 | 4 | 176 |
> Get-Datacenter -PipelineVariable dc
Name
----
CG-CO-SBODEVDC
CG-SO
CG-ZZ
CG-CL
CG-NO
CG-NL
CG-CO
It looks as if the pipeline symbol at the end of the Get-Cluster line was dropped.
Can you attach the code as you are running it?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
I have attached the script I used.
1. I'd like to isolate it to only look at the datacenter "CG-SO" and not my entire environment as well.
2. Export to csv.
3. Pipeline symbol was not dropped (dang, that would have been an easy fix).
Get-Datacenter -PipelineVariable dc |
Get-Cluster -PipelineVariable cluster |
Get-VMHost |
Get-VirtualPortGroup |
Select @{N = 'Datacenter'; E = {$dc.Name}},
@{N = 'Cluster'; E = {$cluster.Name}},
Name, VlanId,
@{N = 'VMCount'; E = {($_ | Get-VM).Count}} |
Group-Object -Property Datacenter, Cluster, Name |
ForEach-Object -Process {
$_ | Select @{N = 'Datacenter'; E = {$_.Name.Split(',')[0].Trim(' ')}},
@{N = 'Cluster'; E = {$_.Name.Split(',')[1].Trim(' ')}},
@{N = 'Portgroup'; E = {$_.Name.Split(',')[2].Trim(' ')}},
@{N = 'VlanId'; E = {$_.Group[0].VlanId}},
@{N = 'VMHostCount'; E = {$_.Count}},
@{N = 'VMCount'; E = {($_.Group | Measure-Object -Property VMCount -Sum).Sum}}
}
Strange error in that case.ith this version.
Try with version
Get-Cluster -PipelineVariable cluster|
Get-VMHost |
Get-VirtualPortGroup |
Select @{N = 'Datacenter'; E = {$dc.Name}},
@{N = 'Cluster'; E = {$cluster.Name}},
Name, VlanId,
@{N = 'VMCount'; E = {($_ | Get-VM).Count}} |
Group-Object -Property Datacenter, Cluster, Name |
ForEach-Object -Process {
$_ | Select @{N = 'Datacenter'; E = {$_.Name.Split(',')[0].Trim(' ')}},
@{N = 'Cluster'; E = {$_.Name.Split(',')[1].Trim(' ')}},
@{N = 'Portgroup'; E = {$_.Name.Split(',')[2].Trim(' ')}},
@{N = 'VlanId'; E = {$_.Group[0].VlanId}},
@{N = 'VMHostCount'; E = {$_.Count}},
@{N = 'VMCount'; E = {($_.Group | Measure-Object -Property VMCount -Sum).Sum}}
} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD I get the same error. I'm getting a peer to run to see if it's my environment or version of powercli.
Are you sure you have the required rights on all resources in that datacenter?
Could it be that you have a cluster without ESXi nodes?
Which PowerCli version are you using?
And from which platform (OS + PS version)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference