Running openssl commands in PowerShell Running openssl commands in PowerShell powershell powershell

Running openssl commands in PowerShell


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.


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

http://www.jonathanmedd.net/2013/07/making-native-executables-in-windows-run-quietly-in-powershell.html

Which shows to simply put

2>&1 

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.