简体   繁体   中英

Why does PowerShell ISE asks to confirm when an executable outputs to stderr?

I am debugging a powershell script in ISE and there I call the sysinternals pskill utility.

For some reason, PowerShell opens the following dialog:

在此处输入图片说明

Why? How can I configure it not to show the dialog, but just run the script as I intend?

EDIT 1

The problem is reproduced very easily:

  1. Run ise -noprofile
  2. Inside ise command prompt run pskill -h

Here is the result:

在此处输入图片说明

Although, there is no dialog, but there is error output, which I suppose is the cause for the dialog in my other scenario. So, the question is what is the cause for the error output?

It seems that pskill sends part of its help screen to the stderr, indeed, observe:

C:\Dayforce\utils> .\pskill.exe -h

PsKill v1.15 - Terminates processes on local or remote systems
Copyright (C) 1999-2012  Mark Russinovich
Sysinternals - www.sysinternals.com

Usage: pskill [-t] [\\computer [-u username [-p password]]] <process ID | name>
     -t    Kill the process and its descendants.
     -u    Specifies optional user name for login to
           remote computer.
     -p    Specifies optional password for user name. If you omit this
           you will be prompted to enter a hidden password.

C:\Dayforce\utils> .\pskill.exe -h 2> $null
Usage: pskill [-t] [\\computer [-u username [-p password]]] <process ID | name>
     -t    Kill the process and its descendants.
     -u    Specifies optional user name for login to
           remote computer.
     -p    Specifies optional password for user name. If you omit this
           you will be prompted to enter a hidden password.

C:\Dayforce\utils>

So, it seems that I only had the problem with pskill, because it outputs to stderr and ISE considers it a good reason to open a dialog. I fix it with the -nobanner command line option.

But how to fix it in general? I do not want ISE to open any dialog if a command outputs stderr, which in itself may not be a good taste, but does not mean there is an error.

In order to suppress the confirm box when you are using Write-Debug insert this at the top of your script / function :

If ($PSBoundParameters['Debug']) {
    $DebugPreference = 'Continue'
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM