PowerShell Tip: Out-Null is to PowerShell What Duct Tape is to Mouth

By Michael Flanakin @ 11:15 AM :: 16629 Views :: PowerShell :: Digg it!

There are a number of commands in PowerShell that aren't as "quiet" as you may want them to be. Sometimes, there are parameters to supress output, but not always. Fortunately, we have Out-Null. While seemingly simple, this is a priceless cmdlet. I use it when writing scripts to keep the output clean.

Perhaps the simplest explanation of this cmdlet is to show a very common function, md, which creates a new directory. For the uninitiated, this function is available to support backwards-compatibility to DOS. You may have caught that I referred to this as a function and not an alias to a cmdlet. Based on that, if you want to see what the function is, simply use Get-Content.

PS C:\Flanakin> Get-Content function:md
param([string[]]$paths); New-Item -type directory -path $paths

As you can see, md simply makes a call to New-Item and tells it to create a directory with the specified path. Pretty simple. Here's what the output looks like.

PS C:\Flanakin> md noisy

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\Flanakin

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         1/27/2009   2:51 PM            noisy

PS C:\Flanakin>

I don't know about you, but that's a lot more than I really care to know. Oh, and note the 6 extra lines. Bleh! Luckily, Out-Null will save us.

PS C:\Flanakin> md quiet | Out-Null
PS C:\Flanakin>

That's it! You gotta love something so simple.