Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running openssl commands in PowerShell

I'm executing the following command in PowerShell:

Invoke-Expression "openssl pkcs12 -in $certCN.pfx -nocerts -nodes -out $certCN.key -password pass:1111"

It works fine, however the output from openssl is causing ugly console errors:

openssl : MAC verified OK
At line:1 char:1
+ openssl pkcs12 -in www.mywebsite.com.pfx -nocerts -node ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MAC verified OK:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

What's the best way to execute this OpenSSL command and have the output ignored or at least not interpreted as a command?

like image 325
Dominic Brunetti Avatar asked Nov 08 '17 22:11

Dominic Brunetti


1 Answers

You don't need Invoke-Expression (in fact, it's not recommended except in specific cases because it is susceptible to injection). Just run the command and quote the parameters where you need variable string expansion:

openssl pkcs12 -in "$certCN.pfx" -nocerts -nodes -out "$certCN.key" -password pass:1111

To ignore the output of the command, one common technique is to pipe to Out-Null.

like image 195
Bill_Stewart Avatar answered Oct 05 '22 04:10

Bill_Stewart