Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See PowerShell Verbose output in Visual Studio Code

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?

like image 397
MikeBaz - MSFT Avatar asked Oct 22 '17 12:10

MikeBaz - MSFT


People also ask

How can I see all the outputs in VS Code?

Go to File>Preferences>Setting and search for the Scrollback setting and increase the value to get the number of lines of output you want. This worked for me. Save this answer. Show activity on this post.

How do I view PowerShell in Visual Studio?

Start in Visual Studio Open Visual Studio. On the menu bar, select Tools > Command Line > Developer Command Prompt or Developer PowerShell.

What is verbose output in PowerShell?

Typically, the verbose message stream is used to deliver more in depth information about command processing. By default, the verbose message stream is not displayed, but you can display it by changing the value of the $VerbosePreference variable or using the Verbose common parameter in any command.

How do I Debug PowerShell using Visual Studio code?

First look at the PowerShell Debugger in Visual Studio Code. Press Ctrl+Shift+P (Cmd+Shift+P on Mac) to open the PowerShell extension's Examples folder, type PowerShell open examples, and then press Enter. After the Examples folder has loaded, open the DebugTest.


1 Answers

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

like image 199
mklement0 Avatar answered Sep 30 '22 21:09

mklement0