4

Is there a way to get Write-Debug to print a blank line without printing DEBUG: Ex:

Write-Debug `n

Write-Debug `n # additional parameters or command here

Write-Debug `n

Output :>

DEBUG:

DEBUG:

2 Answers 2

4

You could do this by creating function Write-Debug like this:

PS> function Write-Debug {
  [cmdletbinding()]
  param($message)
  if (!$message) { 
    write-host; return 
  }
  $cmd = get-command -commandType cmdlet Write-Debug
  & $cmd $message
}

PS> Write-Debug 'this is test'; Write-Debug; Write-Debug '3rd row'
DEBUG: this is test

DEBUG: 3rd row

If you create new function with the same name as a cmdlet, you hide the original cmdlet, because PowerShell will first try to find function with name Write-Debug. If there is none, PowerShell tries to find cmdlet with that name. (generally the first type of command that PowerShell tries to find is alias, not a function).

Sign up to request clarification or add additional context in comments.

Comments

4

Unfortunately not. This "debug:" prefix is controlled by the powershell host, be that powershell.exe or powershell_ise.exe and is not configurable.

Update: you could do something dirty like write out some backspaces.

write-debug "`b`b`b`b`b`b`b      " -debug

1 Comment

Thanks for this answer! I wanted something like that. To improve on it a bit: Just use a single carriage return at the beginning of the line: Write-Debug "`rthis is is a debug message"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.