To All,
We currently run a powershell script to gather details from over 50 separate private vcenter environments for management review on a monthly basis.
This works to gather total 'vcenters/ hosts/ vms/ CPUs' ...
I need to add to the script to see if it can split out the counts per 'location', per Datacenter
For example we have about 8 different datacenters, the vcenter names we use today do hold a naming convention that defines the true location of the equipment.
(Example of vcenter name - 'customername-vctr01.NYC.domainname.com'
Any idea how we could tweak the script to break the totals out per datacenter?
Example of the script below:
$vcenterlist=@()
$vcenterlist+=,@("vcenterip","username","password","customername")
$vcenterlist+=,@("vcenterip","username","password","customername")
$vcenterlist+=,@("vcenterip","username","password","customername")
$vcenterlist+=,@("vcenterip","username","password","customername")
$vcenterlist+=,@("vcenterip","username","password","customername")
disconnect-viserver -server * -force -confirm:$false >$NULL 2>&1
$vms=@()
$hosts=@()
$cpus=0
foreach ($vcenter in $vcenterlist) {
connect-viserver -server $vcenter[0] -user $vcenter[1] -password $vcenter[2] >$NULL 2>&1
$datacenter=(get-datacenter).name
"vCenter=" + $vcenter[0] + " alias=" + $vcenter[3] + " datacenter=" + $datacenter
$somevms=get-vm
$somehosts=get-vmhost
"VMs="+$somevms.count
"Hosts="+$somehosts.count
$somecpus=0
$somehosts|%{$somecpus+=$_.extensiondata.hardware.cpuinfo.numcpupackages}
"CPU Sockets="+$somecpus
$vms+=$somevms
$hosts+=$somehosts
$cpus+=$somecpus
$servinst = get-view ServiceInstance
$vcver = $servinst.content.about.version
"vCenter Version = $vcver"
# $fname="C:\private\private-$($vcenter[3]).csv"
# $somevms|select * |export-csv $fname -notypeinformation
disconnect-viserver -server * -force -confirm:$false >$NULL 2>&1
}
"Total vCenters = "+$vcenterlist.count
"Total VMs = "+$vms.count
"Total Hosts = "+$hosts.count
"Total CPU Sockets = "+$cpus
#$vms|select *|export-csv private-vms.csv -notypeinformation
#$hosts|select *|export-csv private-hosts.csv -notypeinformation
If you can provide the rule to extract the location (= datacenter ?) from the VC name, you could group the result on this value (with the Group-Object cmdlet).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference