VMware Cloud Community
CoolonVsphere
Enthusiast
Enthusiast
Jump to solution

Script for LUN Utilization in CSV format

Hi All

We are looking for Script which will provide lun Utilization in below format.

This will help in provide lun details like vmfs type/ last update /Capacity of Lun/Capacity of lun(inGB) /Free space/Used space and % of lun utilization

All luns are managed by our centrally vcenter server. I am not expert in powercli hopefully from this forum i Will get assistance 🙂

 

   

LUN Identification NameTypeLast UpdateCapacity (GB)Free (GB)Used Space(GB)% of LUN Utilization
LUN01_vol01VMFS33/6/2017 1:30:52 PM1863.68901.04962.6451.65
LUN02_vol01VMFS33/6/2017 1:30:51 PM1536597.64938.3661.09

Thanks in Advance

PS

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Not sure what you want to see under Last Update.

Get-Datastore |

Select Name,

    @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}},

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

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

    @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,1)}},

    @{N='% of LUN Utilization';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB * 100,1)}}


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

View solution in original post

13 Replies
LucD
Leadership
Leadership
Jump to solution

Not sure what you want to see under Last Update.

Get-Datastore |

Select Name,

    @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}},

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

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

    @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,1)}},

    @{N='% of LUN Utilization';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB * 100,1)}}


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

CoolonVsphere
Enthusiast
Enthusiast
Jump to solution

Thanks for LuCD

Really appreciate for the quick reply ...

Script is running but not sure where its getting saved in csv format. (searced in desktop and C drive too not found the CSV output)

and also if we can add few more columns like  next to   @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}}

  

NameIdentifierPath IDLUN
DELL Fibre Channel Disk (naa.690b11c0003d8d6600000887519c23fa)naa.690b11c0003d8d6600000887519c23favmhba1:C0:T0:L21101
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

This is with the Identifier field included, and an export to a CSV.

Get-Datastore |

Select Name,

    @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}},

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

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

    @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,1)}},

    @{N='% of LUN Utilization';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB * 100,1)}},

    @{N='Identifier';E={$_.ExtensionData.Info.Vmfs.Extent[0]}} |

Export-Csv report.csv -NoTypeInformation -UseCulture

The Path Id for a datastore can be different per VMHost.

How will you display that? This is for datastores that are shared between multiple VMHosts.


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

CoolonVsphere
Enthusiast
Enthusiast
Jump to solution

Thanks now csv is generated. You are right Path Id for a datastore can be different per VMHost. So this one we donot required.

can it possible to have datastore LUN number  all added in new Column.

LucD
Leadership
Leadership
Jump to solution

I'm afraid the LUN number can also be different per VMHost.

The only unique value is the Identifier afaik.


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

Reply
0 Kudos
RAJ_RAJ
Expert
Expert
Jump to solution

Hi ,

We can remove the Identifier  also  or  is it will affect on something ?

Like below

Get-Datastore |

Select Name,

    @{N='Type';E={"$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)"}},

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

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

    @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,1)}},

    @{N='% of LUN Utilization';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB *100,1)}} |

    Export-Csv report.csv -NoTypeInformation -UseCulture

RAJESH RADHAKRISHNAN VCA -DCV/WM/Cloud,VCP 5 - DCV/DT/CLOUD, ,VCP6-DCV, EMCISA,EMCSA,MCTS,MCPS,BCFA https://ae.linkedin.com/in/rajesh-radhakrishnan-76269335 Mark my post as "helpful" or "correct" if I've helped resolve or answered your query!
Reply
0 Kudos
davejohn7
Contributor
Contributor
Jump to solution

Hi LucD,

I would like to get these reports in mail. Is it possible ??

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, try like this

$report = Get-Datastore |

Select Name,

@{N = 'Type'; E = { "$($_.Type)$($_.ExtensionData.Info.Vmfs.MajorVersion)" } },

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

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

@{N = 'UsedSpaceGB'; E = { [math]::Round($_.CapacityGB - $_.FreeSpaceGB, 1) } },

@{N = '% of LUN Utilization'; E = { [math]::Round(($_.CapacityGB - $_.FreeSpaceGB) / $_.CapacityGB * 100, 1) } }

$sMail = @{

   To = 'me@domain'

   From = 'report@domain'

   Subject = 'Datastore Report'

   SmtpServer = 'mail.domain'

   Body = $report | ConvertTo-Html | Out-String

   BodyAsHtml = $true

}

Send-MailMessage @sMail


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

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Is there any reason why the Identifier column is only showing "

VMware.Vim.HostScsiDiskPartition

" as the result ?

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try changing that line to

@{N='Identifier';E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}} |


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

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Thank you Luc, it is working as expected 🙂

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
davejohn7
Contributor
Contributor
Jump to solution

Hey LucD,

I would like to know where to run this script.

Hope i need to run it in a server which has access to the Vcentre ??

Do mention me where to run it ? I'm from storage background and because we don't have any specifc SNMP to monitor the LUN utilization, we would like to have these scripts to get the LUN utilization !! So kindly get back to me on this.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, you can run the script on any host that can connect (Connect-VIServer) to the vCenter.

It doesn't really matter if it is a workstation or a server.

The host where you run the script, needs to have PowerShell and the VMware PowerCLI modules installed.


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

Reply
0 Kudos