Hello all,
I am looking for a report which gives me the Cluster name, Hostname , number of machines in the cluster.
Does any one has this .....
Thanks
Shankar.G
I'd start here. Ask if you need more.
Hal Rottenberg
Co-Host, PowerScripting Podcast (http://powerscripting.net)
I wrote this the other day which will give you the machines in a cluster:
Get-VIServer yourservername
get-cluster | %{$cluster = $_; get-vm -Location $_ | %{$vm = $_; Write $vm.name $cluster.name}}
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
VMware, Citrix, Microsoft Consultant
UK
I was only looking for Numbers like below...
Cluster Name #of VMs Datastore Name Datastore Capacity Datastore Freespace
Cluster A 10 Datastore1 200 Gig 50 Gig
--glk
Cluster Name #of VMs Datastore Name Datastore Capacity Datastore Freespace
Cluster A 10 Datastore1 200 Gig 50 Gig
This should do it, but I only have one cluster handy. Not sure how it'll look with more, please test.
foreach ( $cluster in Get-Cluster ) { $cluster | select Name, @{ N = "VmCount"; E = { ( $_ | Get-VM ).Length } } | Format-Table -AutoSize $cluster | Get-VMHost | Get-Datastore }
>Hal Rottenberg
Co-Host, PowerScripting Podcast (http://powerscripting.net)
Hi,
Please try the below script to get the Cluster name, Hostname , number of machines in the cluster
$server = get-viserver -server
Write-Output "server cluster #Virtual Machines"
foreach($clu in (Get-Cluster) )
{ Write-Host $server.Name " " $clu.Name " " (Get-VM -Location $clu).Length }
I hope it resolves your issue.
Thanks
Niket
Can we include the Datastores also in this report
Right now using the below script:
foreach($clu in (Get-Cluster) )
{ Write-Host $server.Name " " $clu.Name " " (Get-VM -Location $clu).Length }
We get the Cluster name and number of machines can we get the total size, and free space included in the same report. I have multiple datastores attached to the same cluster.
--Pls help
Hi,
Please try the below script to get the data of datastore as well. I made small changes in the format of report.
$server = get-viserver -server
foreach($clu in (Get-Cluster) ) {Write-Output "" ; Write-Host "Cluster Name:- " $clu.Name ; Write-Host "Server Name:- " $server.Name ; Write-Host "#Virtual Machine:- " (Get-VM -Location $clu).Length ; Write-Host "----
" ; Get-Datastore -Entity (Get-Cluster -Name $clu) }
I hope, it resolves your issue.
Thanks
Niket
hei,
The query is giving me the number of virtual machines but it is not able to fetch the Datastores it is throwing error message as below :
"The argument cannot be null or empty."
The argument cannot be null or empty.
At line 7, position 22
Get-Datastore -Entity (Get-Cluster -Name $clu) }
I have tried removing the Entity field but still i am not able to fetch the data . and also is there any way that i can get these content into a varaibles like
all the cluster names to a $variable like that because i am trying to export these reults to a SQL express database..
--Shankar
Get-Datastore only accepts Datacenters, VMs or VMhosts for the -Entity parameter.
But we can use an in-between cmdlet (Get-VM).
foreach($clu in (Get-Cluster) ) { Write-Output "" Write-Host "Cluster Name:- " $clu.Name Write-Host "Server Name:- " $server.Name Write-Host "#Virtual Machine:- " (Get-VM -Location $clu).Length Write-Host "--------------------------" Get-Cluster -Name $clu | Get-VM | Get-Datastore }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is not giving the exactly what i am looking for
i am looking for Cluster Name , VMHost, # VMs, Datastore. Name , Datastore.CapacityMB, Datastore.Freespace.
With the above scripts given i am able to get the Cluster Name # VMs and also i can get the VMHost by doing $clu | Get-vmhost | Select Name, but when i am using like
foreach ($clu in (get-cluster)) {
$clusname = $clu.name
$vmhost = $clu | get-vmhost | select name
$vmhosted = (get-vm -location $clu).Length
write-host "$clusname, $vmhost, $vmshosted"
}
i am getting the results for $clusname and #vmshosted but not $vmhost
Please help and also I am not able to include the get-datastore for each cluster.
===========================
output for vmhost is coming like
VMware.VimAutomation.Client20.ClusterImpl | Get-VMHost | select Name
==============================
--Shankar
Below script would give you the HostName in the cluster.
$server = connect-viserver -server
foreach($clu in (Get-Cluster) )
{ Write-Output "" ;
Write-Host "Cluster Name:- " $clu.Name ;
Write-Host "Server Name:- " $server.Name ;
Write-Host "#Virtual Machine:- " (Get-VM -Location $clu).Length ;
Write-Host "Host name " (Get-VMHost -Location $clu) ;
Write-Host "----
" ;
Get-Cluster -Name $clu | Get-VM | Get-Datastore }
Thanks
Niket
Ok so this works for what I need but can it be exported to CSV? I tried doing it from the command line but it didn't work.
I basically just need a list of hosts and what datastores are attached canonical and display name
Cheers,
Bradley Sessions
If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".