Using the -verbose common parameter
Invoked a cmdlet with the
common parameter -verbose causes the value of
$verbosePreference to be set to
Continue and consequently
write-verbose commands to print the message.
In order to turn a function into a cmdlet (which automatically has the
-verbose parameter), it must be provided with
[cmdLetBinding()] param(…)].
function writeVerbosely {
[cmdletBinding()]
param()
write-host "Value of `$verbosePreference is $verbosePreference"
write-verbose "This is a verbose message"
write-host
}
writeVerbosely
writeVerbosely -verbose