Posting Pause (plus bonus oneliner)
I’m sorry to announce that I won’t be able to post anything until the beginning of October. But I will be back, so please keep me in your RSS feed or check back here in a month. I’ll be back full-force, with more awesome one-liners, helpful scripts and fantastic functions!
Here’s a one-liner to show off to your colleagues. What do you do when somebody asks you for a printed overview of the top-twenty volumes on your virtual servers with the least free disk space?
You fire up your trusty Powershell of course! You type a single line of code, press enter and tell them to check the printer. How cool is that?
Get-VM | Where { $_.PowerState -eq “PoweredOn” } | Get-VMGuest | Select VmName -ExpandProperty Disks | Select VmName, Path, @{N=”MBFree”;E={[math]::Round((($_.FreeSpace)/1MB),2)}} | Sort MBFree | Select -First 20 | Format-Table -AutoSize | Out-Printer
Very cool indeed!
See you next month!
Hugo
6 Responses to Posting Pause (plus bonus oneliner)
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





its too good…
Select-Object : Cannot expand property “Disks” because it has nothing to expand
.
At line:1 char:72
+ Get-VM | Where { $_.PowerState -eq “PoweredOn” } | Get-VMGuest | Select <<<<
VmName -ExpandProperty Disks | Select VmName, Path, @{N=”MBFree”;E={[math]::Ro
und((($_.FreeSpace)/1MB),2)}} | Sort MBFree | Select -First 20 | Format-Table -
AutoSize
Nothing seems to be easier than seeing someone whom you can help but not helping.
I suggest we start giving it a try. Give love to the ones that need it.
God will appreciate it.
fyi, I featured this one-liner in another PowerWF video http://www.youtube.com/watch?v=bLrRROKFcJE (PowerScripter Integration). Credit given.
Thanks again.
@xcud: Thanks! Cool stuff.
$disks = Get-VMGuest -VM | select VmName -ExpandProperty Disks
#it works well if a VM has only one vDisk
#If a VM has more than one disk, necessary this:
foreach($vmd in $disks){
$row = “” | select Name, capacity, FreeSpace
$row.name = $vmd.VmName
$row.FreeSpace = $vmd.FreeSpace
$row.capacity = $vmd.Capacity
}