Problem solve Get help with specific problems with your technologies, process and projects.

What makes Windows PowerShell unique?

Find out why you should learn and use Windows PowerShell -- even if you are already familiar and comfortable with another scripting language.

A question administrators often ask is "Why Windows PowerShell?" They wonder why they should learn this particular scripting language when they already know – and effectively use – other languages like VBScript or Perl.

The simple answer: Interactive objects. This means more than just having access to objects. The critical point here is that everything in PowerShell is an object.

Although the initial power might not be clear, once you understand how to use PowerShell you will never look at scripting the same. For example, below is code for the task "List unique file extensions" in both VBscript and PowerShell.


Const adVarChar = 200
Const MaxCharacters = 255
Set objRecordSet = CreateObject("ADOR.Recordset")
objRecordSet.Fields.Append "Extension", adVarChar, MaxCharacters
Set objFso = CreateObject("Scripting.FileSystemObject")
if Wscript.Arguments.Count = 0 then
    strFolder = objFso.GetAbsolutePathName(".")
     strFolder = Wscript.Arguments(0)
end if
if not objFso.FolderExists(strFolder) then
    Wscript.Echo strFolder & " not found"
end if
Set objFolder = objFso.GetFolder(strFolder)
For Each objFile In objFolder.Files
    strExtension = objFso.GetExtensionName(objFile)
    objRecordSet.Find "Extension = '" & strExtension & "' "
    If (objRecordSet.BOF = True) OR (objRecordSet.EOF = True) Then
        ' Record not found
        objRecordSet("Extension") = strExtension
        ' skip
    End If
objRecordSet.Sort = "Extension"
Do Until objRecordSet.EOF
    Wscript.Echo objRecordSet.Fields.Item("Extension")


Get-childitem | group-object extension | select-object name

While the code isn't that complicated in VBScript, it is so trivial in PowerShell that it only requires one line of code. But how exactly did PowerShell objects help in this situation? Let's start by breaking down the line of code:


This is a built-in cmdlet that list files and folders in a given path. The key here is that it doesn't just return a string with the information you want but instead returns a collection of robust objects. These objects are then passed along to either the console or to another cmdlet if the | is used (explained in the next bullet).

In the above example, the objects were piped to another cmdlet called group-object. If we had just called Get-ChildItem, Powershell would have sent the objects to the console.


This is the pipe operator. It is used in most shells to pass data from one command to another. PowerShell uses this to pass the objects outputted to other cmdlets. It is important to note that the entire object is passed -- not just what you see.


This takes a collection of objects and sorts them by the specific property. In this case, the property is Extension, but it could have been any of the properties available.


This allows you to pick off the object you want to keep.

But that's not all. If you wanted to not only sort by extension, but also by total file size, that can also be done in only one line:

Get-Childitem -Recurse -ea 0 | ?{!$_.PSIsContainer} | Group-Object Extension | select name,@{n="GroupSize";e={($ | measure-object -sum Length).sum}} | Sort-Object -Descending GroupSize -ea 0

If you're newer to Windows Powershell, the above example may be a bit complicated. Here is the same task in smaller bites:

$ScriptBlock = @{n="GroupSize";e={($ | measure-object -sum Length).sum}} $FilesByExtension = Get-Childitem -Recurse -ea 0 | ?{!$_.PSIsContainer} | Group-Object Extension $FilesByExtension | select-object Name,$ScriptBlock | Sort-Object -Descending GroupSize -ea 0

This example can be taken further and put into a Microsoft Excel spreadsheet. (Check out this Cool demo video and code at to see the full PowerShell example).

Overall, the object nature of Windows PowerShell is powerful and truly makes it a different scripting language.

Brandon Shell has been in the IT industry since 1994. He started out as a PC tech and general fix-it guy for numerous companies. In 2000, Shell joined Microsoft as contractor for the Directory Services team, and he became a full-time employee in 2002. In 2004, Shell left Microsoft to pursue a new position focusing on his real passion, PowerShell. In 2007, he joined the PowerShell MVP ranks, and Shell has spent the past several years building his PowerShell knowledge and helping others build theirs.

Dig Deeper on Windows systems and network management

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.