VMware Cloud Community
lorried82
Enthusiast
Enthusiast
Jump to solution

PowerCLI script to get DatastoreCluster, Datastores and the size info, DataCenter, Clusters

Hello - I am looking to pull the DatastoreClusters and then list the datastores as well with their size (total size, Used space, Free Space, Provisioned, Uncommitted space) and the total number of VM's on that datastore. I would also like to include what datacenter and clusters they are on. Is this possible? I would like to maybe limit what is shown to datastores that are 13% free space or less.

Thanks,

Lorri

0 Kudos
34 Replies
lorried82
Enthusiast
Enthusiast
Jump to solution

looks like it but when I run it nothing is coming up...

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And you are sure you have datastores that would get through the Where-clause?

Perhaps try changing the numbers to other thresholds.

I'll do some more tests as well.


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

0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

Ah yes that was it. I adjusted the thresholds and got some results.  If I also want to add the columns for FreeSpace%, ProvisionedSpace% and Uncommitted%

are my calculations correct?

@{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}},

  @{N='ProvisionedSpace%';E={[math]::Round((($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace +  $_.ExtensionData.Summary.Uncommitted)/1GB)/$_.CapacityGB*100,1)}},

    @{N='UnCommittedGB%';E={[math]::Round(($_.ExtensionData.Summary.Uncommitted/1GB)/$_.CapacityGB*100,1)}},

Thanks so much

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, looks good.


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

0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

This works perfectly thanks so much. One last question I have though is that I am using this alert for few things. One is to send an email, however I only want the email to be sent when there is actual output. How do I add that into logic into the script?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you want to send an email for each datastore that hits the watermarks, or one email for all the datastores, and then only when there are datastores?


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

0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

I just need to have one email for anything that meets the criteria please!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean something like this?

Only when there is something in $report will there be an email

$report = Get-Datastore |

where {((($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB)/$_.CapacityGB) -ge 1.75 -and

        ($_.FreeSpaceGB/$_.CapacityGB) -le 0.05} |

Select @{N='Datacenter';E={$_.Datacenter.Name}},

    @{N='DSC';E={Get-DatastoreCluster -Datastore $_ | Select -ExpandProperty Name}},

    Name,CapacityGB,

    @{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},

    @{N='ProvisionedSpaceGB';E={

    [math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)}},

    @{N='UnCommittedGB';E={[math]::Round($_.ExtensionData.Summary.Uncommitted/1GB,2)}},

    @{N='VM';E={$_.ExtensionData.VM.Count}}

   

$report | Export-Csv report.csv -NoTypeInformation -UseCulture

if($report){

    Send-MailMessage -To me@domain.com -from you@domain.com -Subject 'Report' -SmtpServer mail.domain.com -Attachments report.csv -

}


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

0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

exactly. perfect.

thank you.

0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

Hi ,

I am new to VMware and PowerCLi topics, I would like to generate a .csv file in following format :

ClusterName | ClusterCapacity | ProvisionedSpace | ClusterOverProvision% | Host OS Type

Thanks in advance.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suggest to open a new thread for your question.
And explain if the values you want to see are only for storage?

Do you mean the ESXi version with 'Host OS Type'?


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

0 Kudos
NageshJ
Contributor
Contributor
Jump to solution

0 Kudos
davejohn7
Contributor
Contributor
Jump to solution

Hi Is there anyway I can send these csv file output to a mail ID ? I'm totally from storage background and i don't know how it works. From storage end, we don't have the SNMP feature of fetching high utilized LUN, so everytime we need to login to almost 15 storage arrays and to fetch the storage details. So I would like to optimize the time here. Is there any way we can get these reports in our mail ?
0 Kudos
rachappachalmi
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

For me also its working fine but i need VM names also along with this out put, is it possible ?

0 Kudos
rachappachalmi
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Its working for me as well but i need VM names along with VM count against datastore, can you help me with this pls ?

0 Kudos