Write Verbose - PowerShell
Overview
Write-Verbose outputs verbose diagnostic information to the host, typically used for debugging and troubleshooting purposes. It provides detailed messages that can help identify and resolve issues in scripts or commands.
Syntax
Write-Verbose [[-InputObject] <PSObject>] [-Message] <string> [-Category] <string> [-Verbose] [-IncludeCallerInfo] [-Bypass] [-Skip] [-Exclude] [-Stream] <string> [-Utc] [-SortOrder] <string>
Options/Flags
-InputObject
Specifies an object to write verbose information about.
-Message
The message to write to the host.
-Category
The category name associated with the message.
-Verbose
Force the command to output verbose messages, even if Verbose preference is not set.
-IncludeCallerInfo
Include caller information in the verbose message.
-Bypass
Bypass the Write-Verbose preference and write the message.
-Skip
Skip writing the message if the Write-Verbose preference is not set.
-Exclude
Exclude writing the message if the Write-Verbose preference is set.
-Stream
The output stream to write the message to.
-Utc
Write the message with a UTC timestamp.
-SortOrder
The sort order of the verbose message entries.
Examples
Output a Verbose Message:
Write-Verbose "This is a verbose message."
Write a Verbose Message with a Category:
Write-Verbose -Message "This is a verbose message." -Category "Troubleshooting"
Output Verbose Messages for All Objects in an Array:
$objects = Get-ChildItem
Write-Verbose -InputObject $objects -Message "Verbose message for each object:"
Common Issues
- Verbose messages not appearing: Ensure that the Write-Verbose preference is set to Verbose or higher.
- Verbose messages not informative: Provide meaningful and detailed messages to help diagnose issues.
- Too many verbose messages: Use the -Skip or -Exclude options to prevent excessive messages if the Write-Verbose preference is not set.
Integration
Write-Verbose can be integrated with other commands using the pipeline. For example, to write verbose messages for the output of a Get-Item command:
Get-Item | Write-Verbose
Related Commands
- Get-Verb: Get the verbs (commands) available in the current PowerShell session.
- Set-Verb: Set the preferences for a specific verb.