I am using Visual Studio Code 1.17.2 with the PowerShell extension (1.4.3). I have Write-Verbose
statements in my code. When I run the PowerShell script, the Verbose
output doesn't seem to go anywhere. How do I request that output be shown?
The simplest approach is to execute
$VerbosePreference = 'Continue'
in the integrated PowerShell console before invoking your script (and executing $VerbosePreference = 'SilentlyContinue'
later to turn verbose output back off, if needed).
From that point on:
running a script (starting it with ( F5 ) or without ( Ctrl+F5 ) the debugger)
highlighting a section of code and running the selection ( F8 )
will make Write-Verbose
calls produce output.
If you want to preset $VerbosePreference = 'Continue'
every time the integrated console starts, put that statement in the $PROFILE
file :
If your VS Code-specific $PROFILE
file already exists, simply run psedit $PROFILE
from the integrated console.
If not, create the file first from the integrated console : New-Item -Type File $PROFILE
Verbose output by default it not shown, you need to declare [CmdletBinding()]
in your function or script to enable the -Verbose
parameter to be passed through in order have the option to display Verbose output.
You can 'cheat' though and pass -Verbose
to Write-Verbose "Hello Verbose" -Verbose
itself and that stream will appear in the console.
(Tested with your two matching versions for VSCode and Extension on Mac (PS6 Beta 8) and can see the verbose output).
function Test-Verbose {
# This enables the function to have '-Verbose'.
[CmdletBinding()]
param()
Write-Output "Hello output!"
# Will only be displayed if 'Test-Verbose' is passed '-Verbose'.
Write-Verbose "Hello verbose"
}
Test-Verbose -Verbose
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.