Windows 2000 Scripting Guide: Free Disk Space
The Windows 2000 Scripting Guide was an invaluable resource for VBScript users. It was one of the things that helped bring scripting into the mainstream of admin activity. It contains a lot of scripting background information but written from a VBScript viewpoint. The example scripts are still incredibly useful - but they are written in VBScript. From a PowerShell users view that doesn't help. I am going to start working through the guide translating the scripts in to PowerShell.
The guide is available on line at http://www.microsoft.com/technet/scriptcenter/guide/default.mspx?mfr=true. Unfortunately the URL doesn't change as you navigate through the guide so I will have to supply navigation pointers as we go.
In the written book we will start at chapter 2 - online we are at
Listing 2.1 - Retrieving Free Disk Space
Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId='C:'" | Format-List Freespace
One line of PowerShell replaces 3 lines of VBScript.
Use Get-WMIObject to pull back the Win32_LogicalDisk class. The -filter parameter can be used to control which disk - deviceid equates to drive letter in this case. Select the Freespace property as that's what we are interested in and use format-list to give a nice display.
It can be expanded to cover all disks by removing the filter
Get-WmiObject -Class Win32_LogicalDisk | Format-Table DeviceID, Freespace -AutoSize
We then add the deviceid to the selected properties and use format-table to display. Autosize will keep the columns from spreading all over the screen.
|Share this post :|