A Simple One-liner today but it shows you how to add information along the pipe line to enable new properties which can be formed using other cmdlets or simple math statements on existing properties:
This one-liner will give you the VM disk or partition sizes for each of your VMs:
ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N="Name";E={$VM.Name}},DiskPath, @{N="Capacity(MB)";E={[math]::Round($_.Capacity/ 1MB)}}, @{N="Free Space(MB)";E={[math]::Round($_.FreeSpace / 1MB)}}, @{N="Free Space %";E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}
Output:
$report = ForEach ($VM in Get-VM ){
($VM.Extensiondata.Guest.Disk | Select
@{N=”Data Center”;E={$vm | Get-Datacenter | Select-Object -ExpandProperty name }},
@{N=”vCenter Server”;E={$vm.ExtensionData.Client.ServiceUrl.Split(‘/’)[2].trimend(“:443″)}},
@{N=”Cluster”;E={$vm | Get-Cluster | Select-Object -ExpandProperty name}},
@{N=”Host”;E={$VM.VMHost}},
@{N=”Name”;E={$VM.Name}},DiskPath,
@{N=”Capacity(MB)”;E={[math]::Round($_.Capacity/ 1MB)}},
@{N=”Free Space(MB)”;E={[math]::Round($_.FreeSpace / 1MB)}},
@{N=”Free Space %”;E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})
}
$report | Export-Csv D:\SZEMMALI\scripts\vmware-collect\report.csv -NoTypeInformation -UseCulture
Is there a way to get – VM | datastore | datastore capacity| datastore free space | ?
Pingback: Getting VMware guest disk information – HyperPowered Thoughts
Great Script , in need to export the output for this script in .csv , please can you help
Pingback: Menampilkan Informasi Pada VMware Menggunakan PowerShell – nyubi.net
Hi All,
I tried the script and trying to export it in html, but the data is not coming in html.. can any one help me in that.
ForEach ($VM in ( Get-VM |Get-View)){($info = $VM.Guest.Disk |Select @{N=“Name“;E={$VM.Name}},DiskPath, @{N=“Capacity(GB)“;E={[math]::Round($_.Capacity/ 1GB)}}, @{N=“Free Space(GB)“;E={[math]::Round($_.FreeSpace / 1GB)}}, @{N=“Free Space %“;E={[math]::Round(((100 * ($_.FreeSpace))/ ($_.Capacity)),0)}})|Format-Table} ConvertTo-Html | Set-Content C:\Users\ABC\Desktop\FreeSpaceFinal.htm
Hello,
nice script! 🙂
I would like to comment that i used your script to make this:
https://communities.vmware.com/blogs/VirtuallyAnITNoob/2014/04/23/report-vms-guest-disks-with-less-than-20-free-using-powercli
Best regards,
Pablo
hi
i need some help
im using this script for specific VMs in vApp
ForEach
($VM in (Get-VApp “My vApp” | Get-VM |Get-View)){($VM.Guest.Disk
|Select @{N=“Name“;E={$VM.Name}},DiskPath,
@{N=“Capacity(GB)“;E={[math]::Round($_.Capacity/ 1GB)}}, @{N=“Free
Space(GB)“;E={[math]::Round($_.FreeSpace / 1GB)}}, @{N=“Free Space
%“;E={[math]::Round(((100 * ($_.FreeSpace))/
($_.Capacity)),0)}})|Format-Table}
i want to add “if” option that send me email when the “free Space %” is lower than 15
please help
This is now called PowerCLI and can be downloaded from http://vmware.com/go/PowerCLI
I read about VI Toolkit, but cannot find a download URL anywhere.
Can you give me an idea from where to obtain it?
I am looking for a script that will list vmdk type (Thin, Lazy Zero Thick, Eager Zero Thick) for all the guests.
when I run this one liner it format on the screen as a list rather than the table that is displayed above. adding format-table does not help either
how to capture NVRAM size details
Great script .. but how can I find all VMS (HARD DISK )info withing a particular Cluster
Great script .. but how can I find all VMS info withing a particular Cluster
you can get with this below script
Connect-VIServer
$AllVMs = Get-VM | Get-View | Where {-not $_.Config.Template}
$SortedVMs = $AllVMs | Select *, @{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
}
}}
} | Out-GridView
Disconnect-VIServer -Confirm:$False
Connect-VIServer
$AllVMs = Get-VM | Get-View | Where {-not $_.Config.Template}
$SortedVMs = $AllVMs | Select *, @{N=”NumDisks”;E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
}
}}
} | Out-GridView
Disconnect-VIServer -Confirm:$False
Alan,
This is a one liner that works perfect.
Get-VM | Where-Object {$_.Name -match “vmware”} | select Name , powerstate , Numcpu , memorymb
but i wanted to add the “VM IP” and “VM creation date” to the same. is it possible?
Hello friends,
It’s really helping to my work, i want IP & HostName also can any one help me on this ?
Thanks in advance.
Pingback: Virtu-Al | Virtually everything is poshable
Hi there,
Im trying to get this in an Script… which gets the Size and writes all VM’s with Free Diskspace less then an value in an HTML or textfile to E-Mail it…
Anybody.. could help… started today with PowerCLI / Powershell
For the E-Mail List I would like to use the Variable $users
and for the WarningValue $percentofWarning…
The E-Mail sending-sequenze using the Content of the txt/html is already done..
Any ideas?
regs
Morry
Fantastic – Thanks very much – I’ve been trying (and not getting very far) to put something like this together.
Question – Is it overly complicated to add additional code to update the annotation field for each VM with this information?
Regards
Grant
As promised: http://www.virtu-al.net/2010/01/27/powercli-virtual-machine-disk-usage/
@Lars, @Abdul,
Yes I have the code which exports this to CSV, I will post it over the next couple of days.
Did you find a way to export it to a file?
Hi Al,
Greate script, it helps me a lot!
Is there a way to export the output to a .XLS file?
Pingback: VMTN Podcast number 70, Storage… » Yellow Bricks
Yes there is a way but i doubt it will be a one-liner, I will try and work on it when I get 5 mins 🙂
This is a very nice script, thanks.
Is there a way to have this exported to a file?
@Roger
Hmmm, well spotted, will work on that one, no promises it will be a single line though 🙂
Hello Al,
You script(oneliner) works great for windows guests but only shows the Boot volume for a Linux machine, do you know a way how to list the VMDK sizes for a Linux VM ?
Roger
@Albert Widjaja
Apparently this is a bit of an issue with PowerGui, if you are running this through the PowerGui editor then try running it by pushing Ctrl + F5 rather than just F5 or pushing the play button. (Thanks LucD)
Hope that helps.
Alan
Dear Sir,
Thanks for creating and sharing such a great cmdlet, however when
I execute your script in PowerGUI
after specifying: Connect-VIServer ESXi1
i got error:
Operation is not valid due to the current state of the object.
At :line:0 char:0
is it because I’m running ESXi 3.5 u4 ?
thanks.
Great Simple Script. Thanks