With PowerShell, how can I get Write-Debug output to the console?

I am learning PowerShell and using Write-Host to check the assignment of variables in a new PowerShell script file. Then I read an article that said it was a bad idea.

So, in my .ps1 file, I replaced the statements as follows:

Write-Host "Start"
Write-Host "End"

... with this:

Write-Debug "Start"
Write-Debug "End"

But when I ran the saved script in Windows PowerShell ISE, nothing was output to the console. I -debugrefer to the statement that the script calls, something like this:

PS E:\trialrun> .\MyScript.ps1 -debug

But then again, the output is not written to the console. Apparently I'm using Write -debug incorrectly. How can I get debug output for writing to the console?

+14
source share
3 answers

; :

  • $DebugPreference = 'Continue', Write-Debug.

  • , $DebugPreference , $DebugPreference = 'SilentlyContinue'


Write-Debug, :

$DebugPreference - SilentlyContinue, , Write-Debug .

-Debug, $DebugPreference , Windows PowerShell Inquire, Write-Debug , , , .
PowerShell Core (v6+) ( ) Continue.

  • -Debug, , [CmdletBinding()] param(), .

Windows PowerShell " " Write-Debug -call , $DebugPreference = 'Continue'. , PowerShell Core (v6+) .

+25

CmdletBinding script, ( -Debug):

[CmdletBinding()]
param()

Write-Debug Start
Write-Debug End

about_Functions_CmdletBindingAttribute

+11

Write-Output Write-Host, . Write-Verbose - .

. : Write-Host

, . , , .

0

Source: https://habr.com/ru/post/1682158/


All Articles