Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 34890

Scripting Tips and Tricks: Write-Verbose

$
0
0

A couple of weeks ago I reminisced about message boxes. In that post I mentioned that I use the Write-Verbose cmdlet in scripts. Here's how why and how...

Why?

Information sent to the verbose message stream can aid troubleshooting. It's also great for tracking the progress of a script or function.

How?

With version 2 of PowerShell 'advanced functions' made their debut. These are functions that act like cmdlets. To enable this goodness we use the CmdletBinding statement. In doing so we have easy access to a wealth of additional, familiar functionality, e.g. common parameters.

Common parameters are parameters that can be used with any cmdlet. One of these is -Verbose...

Get-WindowsFeature-NameGPMC-Verbose


 

This is how we make use of Write-Verbose in a very simple advanced function:

functionWrite-VerboseStream {

[CmdletBinding()]

Param ()

Write-Verbose"YAY!"

}

 

Running the Write-VerboseStream function with the -Verbose parameter results in a message to screen.  

 

As stated earlier we need the CmdletBinding statement to access the -Verbose common parameter. We also have to include the Param statement. Notice how both are able to accept additional arguments - ( )

 

Chose words carefully; talk economically.

Write scripts meticulously and embrace verbosity! 

 

More to come on CmdletBinding and Param...

 

 

 


Viewing all articles
Browse latest Browse all 34890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>