Posted by: Preetam | December 15, 2006

One Liner New ERA

I guess with powershell new era has started, that is all about one liners. Code which takes about min 10 lines in VBScript is reducing to one line and with much better output. below is one of the example which finds out local drive on the computer and list there properties

Power shell code

$process=get-wmiobject -class win32_logicaldisk where{$_.drivetype -eq 3}

foreach($proc in $process) {

write-host VolumeName :-> $proc.VolumeName

write-host Filesystem :-> $proc.filesystem

write-host Filesize :-> $proc.size

write-host Freespace :-> $proc.FreeSpace

Write-host ========================


Output is below

VolumeName :->
Filesystem :-> NTFS
Filesize :-> 20974428160
Freespace :-> 2152263680
VolumeName :-> Windows2004
Filesystem :-> NTFS
Filesize :-> 39028953088
Freespace :-> 11977916416

Get-WmiObject -Class win32_logicaldisk | where{$_.drivetype -eq 3} | sort size (Just one line………..)

OutPut is Below

DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 2152235008
Size : 20974428160
VolumeName :

DeviceID : E:
DriveType : 3
ProviderName :
FreeSpace : 11977916416
Size : 39028953088
VolumeName : Windows2004

But power of powershell is explored in different ways I know. I would soon get use to it and come with more examples like this.

Technorati tags:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: