Posts

Showing posts with the label Verbose

Verbose Parameter Passing to cmdlet inside Function

Well, almost all powershell cmdlets, functions and workflows have a Verbose parameter that displays more information about what the command is doing during it's execution. But how are we going to take advantage of this parameter when building our own functions and scripts? First of all, we have to include the "cmdletBinding()] statement. This will add the -Verbose switch to the function/script and when we call the function with that script the output from the command "Write-Verbose" will be displayed. Take the following function for example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Function Test { [ cmdletBinding ()] Param ( ) Write-Verbose "Started" Start-Sleep -Seconds 5 Write-Verbose "Completed." } All it does is sleep for five seconds. If we call it without the -Verbose switch it will display nothing. With the -Verbose switch it will display the "Started" message before sleeping a...