Never forget -Verbose again

Working with DSC I am constantly having to type –Verbose on my Start-DscConfiguration calls.  However, I stumbled across this cool feature of PowerShell that I thought I would share that will set the –Verbose switch on all your calls for you.

PowerShell has a collection of Preference Variables that allow you to customize its behavior.  One such variable is named $VerbosePreference. By default the value of $VerbosePreference is “SilentlyContinue” which requires you to supply the –Verbose switch to see any verbose messages written by the cmdlet or function calls.  However, if you simply set:

$VerbosePreference = “Continue”

You can now forego passing the –Verbose switch but all the verbose messages will be displayed.  This combined with the positional Path parameter can drastically reduce the amount of typing for Start-DscConfiguration call.

Before:

Start-DscConfiguration –Wait –Verbose –Path .\Test

After:

Start-DscConfiguration .\Test –Wait

Or you can go that extra mile and create a new Alias for Start-DscConfiguration:

New-Alias –Name sdsc –Value Start-DscConfiguration

Then all you have to type is:

sdsc .\test -Wait

Like all variables, the values that you set are specific to the current Windows PowerShell session. However, you can add them to your Windows PowerShell profile and have them set in all Windows PowerShell sessions.

Comments are closed