PowerShell Oneliner #1

One of the great things about Windows PowerShell, is that it allows us IT Administrators to write relatively simple, single-line commands to retrieve specific information about our servers and present it just the way we want. I will be posting my own PowerShell Oneliners frequently and explain how they work.

Check the size of type 3, logical volumes in GB, the free space in MB and calculate the percentage free space:

Get-WmiObject Win32_logicaldisk |

Where-Object {$_.drivetype -eq 3} |

Format-Table -Property Name,VolumeName,`

@{label=”Size (GB)”;expression={[math]::truncate($_.size/1GB)}},`

@{label=”Free Space (MB)”;expression={[math]::truncate($_.freespace/1MB)}},`

@{label=”Percent Free”;expression={[math]::truncate((($_.freespace/1GB)/($_.size/1GB))*100)}}

First, I use Windows Management Instrumentation (WMI) to get all information available about the logical disks in my computer.

The result is piped to Where-Object, which filters out the objects that represent a volume.

Then I specify the way I want the output to be formatted: which is in a table, with columns showing the Driveletter, Volume Name, Size, Free Space and Percent Free. I am using a trick here to do some calculations on the properties before I display them. You can use the format @{label=”label”;expression={expression}} to achieve this.

By the way: For readability I have truncated the command at the pipeline character and used the line break character ` (backtick) in several other places. You can however put the entire command in a single line and execute it from the PowerShell Command Prompt.

»crosslinked«

Are you Zen?

I consider myself already a pretty calm and organized guy. But sometimes it’s hard to get motivated and do those chores that you wrote down weeks ago. Somehow, there are always more interesting things to do.

I’ve recently discovered a website that discusses ways to get all those important things done without feeling stressed out by the huge to-do list in front of you. Of course prevention is even better, so the site also focussus on ways to simplify your life and keeping the to-do list small and organized.

Go check it out. Tell me what you think.

VI Toolkit is here!

As you will discover, I am a huge fan of the new Windows PowerShell scripting language.

Also, I spend most of my time at work managing and expanding our VMware Virtual Infratructure.

As of today, the best of these two worlds has been combined into the VI Toolkit (for Windows). This toolkit is essentially a set of new commandlets for Windows Powershell which allow you to manage your VMware Virtual Infrastructure. It is currently still in beta, but I think it has huge potential! I’m already testing it and will post some sample scripts soon.

So stay tuned!