VMware Cloud Community
NageshJ
Contributor
Contributor
Jump to solution

PowerCLi script to get ClusterName | ClusterCapacity | ProvisionedSpace | ClusterOverProvision% | Host OS Type in a .csv file of a host cluster not datastore cluster.

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.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
20 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

I would like to get how much total memory assigned to a cluster and provisioned memory of cluster.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

Thanks a lot

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

Hi

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

Perfect for 1 and 2 and I got the result also. thanks a lot

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

Hi

I have run the script by saving it as 3.ps1 file :

IMG_20180726_165618_588.jpg

it is asking as follows :

IMG_20180726_164904.jpg

So I gave number :

pastedImage_2.jpg

in a .csv file I am getting output as follows:

Length

9

pastedImage_3.jpg

but this is not what I want Smiley Sad

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Line 3 and 4 in your screenshot is in fact 1 line.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think you replaced the pipeline symbol ('|') with an equal sign in the last line


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

Silly Mistake :smileyshocked:

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

Ohhhhh Zakaaqu

Really I replaced the "|" (piep line) with "=" Symbol :smileysilly::smileyconfused:

Reply
0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

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 Smiley Happy

Reply
0 Kudos
veera1987
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos