Running openssl commands in PowerShell

windows powershell command

12642 просмотра

2 ответа

440 Репутация автора

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 -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?

Автор: Dominic Brunetti Источник Размещён: 08.11.2017 10:09

Ответы (2)

-5 плюса

440 Репутация автора


And five minutes after I posted this I found THIS article:

Which shows to simply put


at the end of the string to redirect successes and errors to null as such:

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

Works like champ for my needs.

Автор: Dominic Brunetti Размещён: 08.11.2017 10:21

7 плюса

14520 Репутация автора

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.

Автор: Bill_Stewart Размещён: 08.11.2017 10:46
Вопросы из категории :