VMware Cloud Community
kakekmuda
Enthusiast
Enthusiast

How to get Free space disk vm in Cluster

Dear Team Please Help

I want to retrieve the total disk size and free size data c & d and then in certain clusters, for the script please guide me friends

thank you

19 Replies
LucD
Leadership
Leadership

You are talking about the disks in the guest OS?
Do you have VMware Tools installed on all your VMs?


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

Reply
0 Kudos
kakekmuda
Enthusiast
Enthusiast

Dear Mr LucD

Yes i have, but how to get all vm with script ?

Thank You

Tomi Irawan

Reply
0 Kudos
LucD
Leadership
Leadership

If you answered my previous questions with yes, this should do the trick.

$clusterName = 'cluster'

Get-Cluster -Name $clusterName |

Get-VM -PipelineVariable vm |

Get-VMGuest |

Select-Object -ExpandProperty Disks |

Sort-Object -Property Path |

Where-Object{$_.Path -match "^C|^D"} |

Select-Object @{N='VM';E={$vm.Name}},

    Path,

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

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


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

Reply
0 Kudos
kakekmuda
Enthusiast
Enthusiast

Dear Mr LucD

i can't get vm name with right name

maybe look like

Header 1Header 2Header 3
vm satu100 gb50 gb
vm dua50 gb25 gb
vm tiga200

150

Thank You

Reply
0 Kudos
LucD
Leadership
Leadership

Which PowerShell version are you using?

Do a

$PSVersionTable


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

Reply
0 Kudos
kakekmuda
Enthusiast
Enthusiast

Dear Mr LucD

File Already attach

pastedImage_2.png

Thank You

Tomi Irawan

Reply
0 Kudos
LucD
Leadership
Leadership

That is not what I asked, I asked for the PowerShell version.
Can you do

$PSVersionTable

And your PowerCLI version is rather old.
Is there a reason you are still using this old version?


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

Reply
0 Kudos
kakekmuda
Enthusiast
Enthusiast

Dear Mr LucD

Im sorry Sir LucD.

pastedImage_0.png

Thank You

Reply
0 Kudos
LucD
Leadership
Leadership

No problem, just wanted to check you had a PS version that supported the PipelineVariable parameter.

The following will write the result to a CSV file.
Can you check and show me what you mean with the VM name is missing?
Do you run this from the PS prompt or from a .ps1 file?
When I run this, the VM's Displayname is in the CSV file.

$clusterName = 'cluster'

Get-Cluster -Name $clusterName |

Get-VM -PipelineVariable vm |

Get-VMGuest |

Select-Object -ExpandProperty Disks |

Sort-Object -Property Path |

Where-Object{$_.Path -match "^C|^D"} |

Select-Object @{N='VM';E={$vm.Name}},

    Path,

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

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

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
kakekmuda
Enthusiast
Enthusiast

Dear  Mr LucD

Look like the captuire

pastedImage_0.png

Than You

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, gotcha.
Try like this

$clusterName = 'cluster'

Get-Cluster -Name $clusterName |

Get-VM -PipelineVariable vm |

ForEach-Object -Process {

  Get-VMGuest -VM $vm |

  Select-Object -ExpandProperty Disks |

  Sort-Object -Property Path |

  Where-Object{$_.Path -match "^C|^D"} |

  Select-Object @{N='VM';E={$vm.Name}},

    Path,

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

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

} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

kakekmuda
Enthusiast
Enthusiast

Dear Mr LucD

Thank You For your help, after discuss with my team, its more better if when we have more disk to one vm example :

pastedImage_0.png

Header 1Header 2Header 2Header 3
hdd1total sizeusage sizefree space
hdd 2

Thank You so Much Sir LucD God Bless you

Reply
0 Kudos
LucD
Leadership
Leadership

How do you think that can/should be done?

You are asking for a link between the vDisk (the VMDK) and the guest OS partitions.

As I mentioned on several occasions before where this question pops up, there is no foolproof method of establishing that link between a VMDK and guest OS partitions.

A VMDK can have more than 1 partition, a guest OS partition can combine VMDK, part of a VMDK might be visible as spare space in the guest OS....


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

Reply
0 Kudos
kakekmuda
Enthusiast
Enthusiast

im apologize in advance because I didn't know and

for the previous script is there a vm restriction in the data? because not all the VMs in the cluster are recorded.

Thank you

Reply
0 Kudos
LucD
Leadership
Leadership

There could be two reasons why a VM is not in the list.

- the VM doesn't have VMware Tools installed or has been powered for a longer time. Then the Disks property might be empty

- the VM doesn't have drives that start with C or D


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

Reply
0 Kudos
vespavbb
Enthusiast
Enthusiast

Hi,

how can I pipe the PipelineVariable VM with a filter like where {$_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*'}

and is the a why for check each driveletter whats inside the VM, or is the only why like $_.Path -match "^C|^D|^E|^F|^G|^H|^I|^J|^K .....and so on"

Thanks...

ps for linux works diffent or even is not possible?

VCP4,VCP5,VCP6,VCP7,VCP8
Reply
0 Kudos
LucD
Leadership
Leadership

You don't need to use the pipelinevariable for that, you can just insert the Where-clause in the pipeline.

$clusterName = 'cluster'

Get-Cluster -Name $clusterName |

Get-VM -PipelineVariable vm |

where {$_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*'} |

ForEach-Object -Process {

  Get-VMGuest -VM $vm |

  Select-Object -ExpandProperty Disks |

  Sort-Object -Property Path |

  Where-Object{$_.Path -match "^C|^D"} |

  Select-Object @{N='VM';E={$vm.Name}},

    Path,

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

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

} |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Not sure what you mean by "... check each driveletter whats inside the VM ...".
Since the script expands the Disks property, all known disks will be listed.

For Linux the Path will be off the format /folder.
You can filter on that as well, for example

Where-Object{$_.Path -match "^/bin"}


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

vespavbb
Enthusiast
Enthusiast

ah ok thanks,

one more question. I want to ad a Line for something like Warning if free space is under 10% and modify the output to get anly VM´s with freespace under 10%

the output for Warning is allways TRUE ?

ForEach-Object -Process {

  Get-VMGuest -VM $vm |

  Select-Object -ExpandProperty Disks |

  Sort-Object -Property Path |

  Where-Object{$_.Path -match "^C|^D|^E|^F|^G|^H|^I|^J|^K|^L|^M|^N" } |

  Select-Object @{N='VM';E={$vm.Name}},

    Path,

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

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

    @{N='Warning';E={[math]::($_.FreeSpaceGB/$_.CapacityGB) -le 0.10}}

  

}

VCP4,VCP5,VCP6,VCP7,VCP8
Reply
0 Kudos
LucD
Leadership
Leadership

That is because of the Round you are using.

Any value less or equal to 0.5 will be rounded to 0, hence the $true for all those.

Just use

@{N='Warning';E={$_.FreeSpaceGB/$_.CapacityGB -le 0.10}}


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