Search notes:

PowerShell cmdLet Write-Verbose

write-verbose writes text into the verbose stream.

Influencing the result with the preference variable verbosePreference

By default, the content of the verbose stream is not displayed after a pipeline finished executing.
Setting the preference variable $verbosePreference to 'continue' changes that behavior:
function writeVerbosely {
   write-host    "going to write verbosely"
   write-verbose "This is a verbose message"
   write-host
}

$verbosePreference = 'silentlyContinue'
writeVerbosely

$verbosePreference = 'continue'
writeVerbosely
Github repository about-PowerShell, path: /cmdlets/verbose/write/preference-variable.ps1

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
Github repository about-PowerShell, path: /cmdlets/verbose/write/verbose-parameter.ps1

See also

The cmdLet verb write
Powershell command noun: verbose

Index