Making Native Executables in Windows Run Quietly in PowerShell

Sometimes it can still be beneficial to use a native Windows executable rather than a PowerShell cmdlet, either because say the cmdlet doesn’t exist yet or doesn’t have the functionality that you require. Many of these executables  though won’t behave in the way you have become accustomed to PowerShell cmdlets behaving - for instance some maybe noisy in terms of their output.

Take for instance OpenSSL.exe. I was using this the other day to generate some certificates and it’s pretty noisy on its output. This may be fine if nobody ever watches the output of the script you right, but my use was for a function that might well be used interactively. Have a look at this example:

To generate a private key you could run:


Invoke-Expression ".\\openssl.exe req -new -nodes -out c:\\test\\certs\\rui.csr -keyout c:\\test\\certs\\rui.key -config c:\\test\\certs\\esxi.cfg"

Which in the standard PowerShell console produces the following output:

In the ISE, it’s even more noisy and looks horrible.

You can get round this and make things look a whole lot more pleasant by redirecting errors and success output to the success output stream. It’s not the nicest of looking syntax, but you can find all the options here. By using the following option 2>&1 we can quieten things down again.


Invoke-Expression ".\\openssl.exe req -new -nodes -out c:\\test\\certs\\rui.csr -keyout c:\\test\\certs\\rui.key -config c:\\test\\certs\\esxi.cfg" 2>&1

In both consoles we have a nice quiet command: