VMware Cloud Community
sathu0206
Contributor
Contributor

How to use PowerCLI to export the below 10% less than space C drive server details from Vcenter

Hello Everyone,

How to export the below 10% less free space C:\ drive server list using power CLI? I need to get with it .CSV format.

The format looks like the Server name, Drive, Capacity, and Free Space (less than 10%).

Please assist me. Thanks in advance. 

0 Kudos
6 Replies
LucD
Leadership
Leadership

What do you already have?


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

0 Kudos
sathu0206
Contributor
Contributor

@LucD I have the Vcenter information, I need to pull the below 10 %  less than C:\ drive server details from the vcenter.

Tags (1)
0 Kudos
sathu0206
Contributor
Contributor

This is what I found on the internet, I need the results in a format like the one below in CSV or Xslx format.

Format:

Server name, Drive (harddisk 1, 2,3), Free space, Percent free:

 

 

ForEach ($VM in Get-VM | where-object {($_.powerstate -ne "PoweredOff") -and ($_.Extensiondata.Guest.ToolsStatus -Match ".*Ok.*")}){

ForEach ($Drive in $VM.Extensiondata.Guest.Disk) {

$Path = $Drive.DiskPath

#Calculations

$Freespace = [math]::Round($Drive.FreeSpace / 1MB)

$Capacity = [math]::Round($Drive.Capacity/ 1MB)

$SpaceOverview = "$Freespace" + "/" + "$capacity"

$PercentFree = [math]::Round(($FreeSpace)/ ($Capacity) * 100)

#VMs with less space

if ($PercentFree -lt 20) {

$Output = $Output + "Vm: " + $VM.Name + "`n"

$Output = $Output + "Disk: " + $Path + "`n"

$OutPut = $Output + "Free(MB): " + $Freespace + "`n"

$Output = $Output + "Free(%): " + $PercentFree + "`n"

}

$Output

 

0 Kudos
LucD
Leadership
Leadership

Instead of accumulating the data in 1 variable ($output) use a Select-Object and calculated properties instead.
Then pipe the result to a CSV (Export-Csv)


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

0 Kudos
sathu0206
Contributor
Contributor

Sorry for the delay @LucD Can you update the correction and send it to me? i will verify the result 

Tags (1)
0 Kudos
LucD
Leadership
Leadership

I propose you do the update and I can verify if needed.


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

0 Kudos