Verbose Output for PowerShell Functions

by Sep 19, 2013

To add on-demand verbose output to your PowerShell functions, make sure your functions support the common parameters by adding the CmdletBinding attribute. This is the basic template:

function test
{
    [CmdletBinding()]
    param()
} 

Next, add Write-Verbose to implement verbose text messages. They will only be visible when the user specifies –Verbose parameter:

function test
{
    [CmdletBinding()]
    param()

    Write-Verbose "Starting"
    "Doing Something"
    Write-Verbose "Shutting Down"
} 

So when you run it like this, you get only your regular output:

test 

However, if you add -Verbose, you also see your verbose messages:

test -Verbose 

Twitter This Tip! ReTweet this Tip!