Does PowerShell has something like "echo off" and "echo on" trigger?
Asked Answered
E

3

17

cmd/batch file could turn on and turn off "echo". So in PowerShell, I have a bunch of "write-host" output, I want somewhere to turn on / off write-host for debugging convenience.

Does PowerShell has such a function?

Elaterite answered 18/6, 2015 at 7:35 Comment(0)
G
9

The Set-PSDebug cmdlet has -Trace <int> parameter that can be used to same effect as echo on.

Gyron answered 18/6, 2015 at 7:41 Comment(1)
Thanks! So the command is "Set-PSDebug -Off"Sumerlin
J
8

I recommend you simply put

| Out-Null

at the end of any line where privacy matters... it's more or less the same as putting...

@

... at the beginning of any 'batch' line where you want output hidden from users.

Judaic answered 21/2, 2020 at 22:16 Comment(0)
C
3

You should use Write-Verbose instead of Write-Host, this will make your debugging data controlled by the variable $VerbosePreference. This variable has the same value set as $ErrorActionPreference, and the default is SilentlyContinue, which means that no verbose output is generated. You can set this to Continue and then have your verbose output visible.

Crockett answered 18/6, 2015 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.