I need to find the guestos freespace in GB.
when i do
get-vm xxx | get-vmguest | select *
I see this
how do I get only the C drive which should be "Hard Disk 1" and con vert to GB
Try like this
$vms = get-vm -name (Get-Content .\vms.txt)
ForEach ($VM in $vms) {
$VMview = get-vm $VM | get-view
$result = ""| select VM, Diskpath, CapacityGB, FreespaceGB, Freespace_percent
$result.VM = $VM.Name
$cDisk = $VMview.guest.disk| where{$_.DiskPath -match "^C:"}
$result.Diskpath = $cDisk.diskpath
$result.CapacityGB = [math]::Round($cDisk.capacity/1GB)
$result.FreespaceGB = [math]::Round($cDisk.freespace/1GB)
$result.Freespace_percent = [math]::Round($cDisk.freespace/$cDisk.capacity*100,1)
$results += $result
}
$results | ft -auto
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
get-vm **** | get-vmguest | select -ExpandProperty disks
will show you all the disks in GB
You can do
where {$_.Path -match "^C:"} |
Select -ExpandProperty CapacityGB
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
any idea why I am getting this error with the math function?
$results = @()
$vms = get-vm -name (Get-Content .\vms.txt)
ForEach ($VM in $vms) {
$VMview = get-vm $VM | get-view
$result = ""| select VM, Diskpath, CapacityGB, FreespaceGB, Freespace_percent
$result.VM = $VM.Name
$result.Diskpath = $VMview.guest.disk.diskpath
$result.CapacityGB = [math]::Round(($VMview.guest.disk.capacity)/ 1GB)
$result.FreespaceGB = [math]::Round(($VMview.guest.disk.freespace)/ 1GB)
$result.Free
$results += $result
}
$results | ft -auto
Because the Disk property is an array when there is more than 1 drive in the guest OS.
You could do
$vms = get-vm -name (Get-Content .\vms.txt)
ForEach ($VM in $vms) {
$VMview = get-vm $VM | get-view
$result = ""| select VM, Diskpath, CapacityGB, FreespaceGB, Freespace_percent
$result.VM = $VM.Name
$result.Diskpath = $VMview.guest.disk.diskpath
$result.CapacityGB = ($VMview.guest.disk.capacity | %{[math]::Round($_/1GB)}) -join '|'
$result.FreespaceGB = ($VMview.guest.disk.freespace | %{[math]::Round($_/1GB)}) -join '|'
$result.Free
$results += $result
}
$results | ft -auto
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can i just target the C Drive?
Try like this
$vms = get-vm -name (Get-Content .\vms.txt)
ForEach ($VM in $vms) {
$VMview = get-vm $VM | get-view
$result = ""| select VM, Diskpath, CapacityGB, FreespaceGB, Freespace_percent
$result.VM = $VM.Name
$cDisk = $VMview.guest.disk| where{$_.DiskPath -match "^C:"}
$result.Diskpath = $cDisk.diskpath
$result.CapacityGB = [math]::Round($cDisk.capacity/1GB)
$result.FreespaceGB = [math]::Round($cDisk.freespace/1GB)
$result.Freespace_percent = [math]::Round($cDisk.freespace/$cDisk.capacity*100,1)
$results += $result
}
$results | ft -auto
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Lucd. works perfectly
are these powershell commands and what is the pre-requisite to run these commands
These are PowerShell and PowerCLI cmdlets.
You should have PowerShell and the VMware.PowerCLI module installed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
how do I install the vmware powercli module
See VMware Developer Documentation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference