Hi Team,
I am new to VMware and PowerCLi topics, I have 2 host clusters for these 2 clusters I would like to generate a .csv file in following format :
ClusterName | ClusterCapacity | ProvisionedSpace | ClusterOverProvision% | Host OS Type
If the host OS type is an Esxi version, then I don't need Esxi version. If host OS type not an Esxi version then i need Host OS Type in a separate column.
I would like to get the above result by using PowerCLi script.
Thanks in advance.
Ok, this gives the memory values per cluster.
Note that if OverProvision% is below 100%, there is no overprovisioning.
Get-Cluster |
Select Name,
@{N='ClusterCapacityMemGB';E={
$script:cap = [math]::Round($_.ExtensionData.Summary.UsageSummary.TotalMemCapacityMB/1KB,0)
$script:cap}},
@{N='ProvisionedMemoryGB';E={
$script:alloc = ((Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM).VM -Property Config.Hardware.MemoryMB).Config.Hardware.MemoryMB |
Measure-Object -Sum | select -ExpandProperty Sum)/1KB
[math]::Round($script:alloc)}},
@{N='OverProvision%';E={"{0:P0}" -f ($script:alloc/$script:cap)}}
I'm still not sure what you want to display in the HostType column.
A sample output would probably help to clarify.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure what you mean by ClusterCapacity and ClusterOverProvision%.
Can you explain or give an example?
Also still not sure about the Host OS Type.
Do you want to report on the ESXi nodes in the cluster, or the VMs in the cluster?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would like to get how much total memory assigned to a cluster and provisioned memory of cluster.
Ok, this gives the memory values per cluster.
Note that if OverProvision% is below 100%, there is no overprovisioning.
Get-Cluster |
Select Name,
@{N='ClusterCapacityMemGB';E={
$script:cap = [math]::Round($_.ExtensionData.Summary.UsageSummary.TotalMemCapacityMB/1KB,0)
$script:cap}},
@{N='ProvisionedMemoryGB';E={
$script:alloc = ((Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM).VM -Property Config.Hardware.MemoryMB).Config.Hardware.MemoryMB |
Measure-Object -Sum | select -ExpandProperty Sum)/1KB
[math]::Round($script:alloc)}},
@{N='OverProvision%';E={"{0:P0}" -f ($script:alloc/$script:cap)}}
I'm still not sure what you want to display in the HostType column.
A sample output would probably help to clarify.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot LucD
I ran the script, i got the following error (I am using VMWare LAB) :
Unexpected token '$script:cap' in expression or statement.
Unexpected token '$script:alloc' in expression or statement.
And coming to the Host OS Type is : I would like to find what is an Operating System of a Host.
If Esxi is on operating system of a Host, then I don't want to find the Operating System of the Host, in this case I would like to find Esxi version of the Host.
Can you show how you ran this?
A screenshot, including the error message would help.
What host are you talking about?
The cluster ESXi nodes, the VMs running in the cluster....?
Note that if want to report on Host OS for each VM, that your report would look quite different.
Are you for example going to repeat the cluster information on each line?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I have checked the script once again where I have typed then ran script once again, got the output without error
Following is my VMWare LAB pic :
And following are my requirements :
1) Cluster memory capacity, provisioned memory of cluster and over provisioned % of cluster
2) Esxi version and hardware model of a host
3) Find PoweredOff VMs from 150% Over Provisioned cluster
Finally I would like to get the above result into .csv file or excel file.
That's three separate CSV or worksheets I assume?
That data would be hard to combine in 1 CSV.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If we can get the out put in 3 different worksheets in a single workbook (.csv) then that is good.
Otherwise it is okay to get the result in 3 different workbook (.csv) files.
1)
Get-Cluster |
Select Name,
@{N='ClusterCapacityMemGB';E={
$script:cap = [math]::Round($_.ExtensionData.Summary.UsageSummary.TotalMemCapacityMB/1KB,0)
$script:cap}},
@{N='ProvisionedMemoryGB';E={
$script:alloc = ((Get-View -Id (Get-View -Id $_.ExtensionData.Host -Property VM).VM -Property Config.Hardware.MemoryMB).Config.Hardware.MemoryMB |
Measure-Object -Sum | select -ExpandProperty Sum)/1KB
[math]::Round($script:alloc)}},
@{N='OverProvision%';E={"{0:P0}" -f ($script:alloc/$script:cap)}} |
Export-Csv -Path .\cluster-capacity.csv -NoTypeInformation -UseCulture
2)
Get-VMHost | select Name,Version,Build,Model |
Export-Csv -Path .\esx-info.csv -NoTypeInformation -UseCulture
3) This one is not clear to me.
What exactly do you want to report?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect for 1 and 2 and I got the result also. thanks a lot LucD
3rd requirement :
3) I would like to get Powered Off VMs from the Host and this host should be from cluster(where the cluster's OverProvisionedMemory% >=150%)
OutPut table should be as follows :
VMName | PowerState | HostName | Clustername
Ok, got it.
Try like this
$report = foreach($cluster in Get-Cluster){
$cap = $cluster.ExtensionData.Summary.UsageSummary.TotalMemCapacityMB/1KB
$alloc = ((Get-View -Id (Get-View -Id $cluster.ExtensionData.Host -Property VM).VM -Property Config.Hardware.MemoryMB).Config.Hardware.MemoryMB |
Measure-Object -Sum | select -ExpandProperty Sum)/1KB
if($alloc/$cap -ge 1.5){
Get-VM -Location $cluster | where{$_.PowerState -eq 'PoweredOff'} |
select Name,PowerState,@{N='Hostname';E={$_.VMHost.Name}},@{N='ClusterName';E={$cluster.Name}}
}
}
$report | Export-Csv -Path .\cluster-overcommit-vm.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I have run the script by saving it as 3.ps1 file :
it is asking as follows :
So I gave number :
in a .csv file I am getting output as follows:
Length
9
but this is not what I want
Line 3 and 4 in your screenshot is in fact 1 line.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That I pressed enter button to get the complete script in a snapshot.
But when I am running the script I have not taken it into the new line.
I think you replaced the pipeline symbol ('|') with an equal sign in the last line
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Silly Mistake :smileyshocked:
Ohhhhh Zakaaqu
Really I replaced the "|" (piep line) with "=" Symbol :smileysilly::smileyconfused:
Really I replaced the "|" (piep line) with "=" Symbol :smileylaugh:
Sorry Sorry Now I got the result in VMWare LAB
I will do it in my Private LAB and then will let you know the result.
Thanks a lot
Hi LuCD,
Needed your help in addressing my below Query.
1. We have several vcenters and so many different clusters & Datacenters. Help me in a script if i got particular datastore/datastore cluster having space issue to resolve needed one liner or script to get the space utilized and VM's residing in each cluster with the help of Specific datastore/datastore cluster name SO that i can plan for migration to different cluster or vcenter.
2. Similarly for a particular VM, can we get the residing host, cluster, Datacenter, vcenter, Disk(All disks with allocated and free space) & Network adapter(All adapters, Since there are more than 1 NIC adapter per VM) details.
3. If planning for migration, script required to provide the input of VM names and Destination cluster, So that source VM's to be unregister and register in new Cluster of diffeent vcenter and ESXi version. Also for migration of VM's from One cluster of 6.0 to another cluster of 6.5
4. Also any automated schedule script that whenever a host going to not responding or not pinging, need to get those host details in an email along with cluster and vcenter details.
Please help me in addressing above queries.