jingleharish
Contributor
Contributor

vm disk

Hi...

I am in need of a scripts, Which outputs the drive details and the datastores as attached in the sample excel file.

Your help is much appriciated.

0 Kudos
4 Replies
LucD
Leadership
Leadership

If you have the VMware Tools installed on your guests you can use the following script.

Note1: that guests that do not have VMware Tools installed or which are powered off, will only show the guestname in the report.

Note2: the link to a datastore is not obvious. You could for example have 2 or more partitions (C:\,D:\,E:\) on 1 virtual hard disk. Hugo made a script that does this. See his Get VMware Disk Usage with Powershell post.

$report = @()
foreach($vm in Get-VM){
	if($vm.Guest.Disks){
		$vm.Guest.Disks | %{
			$row = "" | Select Name,Diskpath,CapacityGB,"Free SpaceGB","Used SpaceGB","Free %"
			$row.Name = $vm.Name
			$row.Diskpath = $_.Path
			$row.CapacityGB = "{0:n1}" -f ($_.Capacity/1GB)
			$row."Free SpaceGB" = "{0:n1}" -f ($_.FreeSpace/1GB)
			$row."Used SpaceGB" = "{0:n1}" -f (($_.Capacity - $_.FreeSpace)/1GB)
			$row."Free %" = "{0:p1}" -f ($_.FreeSpace/$_.Capacity)
			$report += $row
		}
	}
	else{
		$row = "" | Select Name,Diskpath,CapacityGB,"Free SpaceGB","Used SpaceGB","Free %"
		$row.Name = $vm.Name
		$report += $row
	}
}
$report | Export-Csv "C:\HD-report.csv" -NoTypeInformation -UseCulture

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
FranckRookie
Leadership
Leadership

Hi,

You can try the following:

$Report = @()

$Disks = Get-VM | Where { $_.PowerState -eq “PoweredOn”} | Get-VMGuest | Select VmName -ExpandProperty Disks

ForEach ($disk in $Disks)
{
$DiskDetail = "" | Select-Object VMName, Path, CapacityGB, UsedGB, FreeGB, PercFree
$DiskDetail.VMName = $disk.VMName
$DiskDetail.Path = $disk.Path
$DiskDetail.CapacityGB = [math]::Round($disk.Capacity/1GB,2)
$DiskDetail.UsedGB = [math]::Round(( $disk.Capacity - $disk.FreeSpace )/1GB,2)
$DiskDetail.FreeGB = [math]::Round($disk.FreeSpace/1GB,2)
$DiskDetail.PercFree = [math]::Round( ( 100 * ( $disk.FreeSpace / $disk.Capacity ) ),0 )

$report += $DiskDetail
}

Good luck

Regards

Franck

0 Kudos
jingleharish
Contributor
Contributor

its not displaying datastore for the vmdk's

0 Kudos
LucD
Leadership
Leadership

See Note2 in my reply.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos