Powershell openssl ObjectNotFound in windows server 2012 - powershell

while trying to convert the private key file in PKCS12 format to PEM format (which is used by Wireshark) in two stages by using the openssl tool got the below error
PS C:\OpenSSL-Win64\bin> openssl pkcs12 -nodes -in test_cer123456.pfx -out key.pem -nocerts -nodes
openssl : The term 'openssl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ openssl pkcs12 -nodes -in test_cer123456.pfx -out key.pem -nocerts -nodes
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (openssl:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command openssl was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by
default. If you trust this command, instead type ".\openssl". See "get-help about_Command_Precedence" for more details.
PS C:\OpenSSL-Win64\bin>
Could some one help me on this.?
Note : I was following this post

Powershell doesn't include current directory as a part of search path. The error message actually tells you this and explains what to do (emphasis added):
Suggestion [3,General]: The command openssl was not found, but does
exist in the current location. Windows PowerShell does not load
commands from the current location by default. If you trust this
command, instead type ".\openssl". See "get-help
about_Command_Precedence" for more details.

Related

How do I execute a command with a new .exe in powershell

I want to decrypt a file that is AES encryptet, with a script on powershell. To decrypt it I want to use a openSSL binary, that the script automatically downloads.
When I execute the openssl.exe with start-Process -FilePath "$pwd\openssl\openssl.exe" a new cmd-window opens and I can enter my command to decrypt the file there. (which works I have tested it)
So my question:
Is there a way to execute the command openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new with the .exe without having to manually input it into the new window?
Yes, try this:
& ".\openssl\openssl.exe" aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new
Using Start-Process, you can pass the parameters with -ArgumentList:
Start-Process -FilePath "$pwd\openssl\openssl.exe" -ArgumentList "aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.new"

Sign a file exe windows ¬ Convert .pem to pfx

I am trying to sign a .exe file and I have a certificate and private key in format .pem.
I convert my cert using openssl to format .pfx
openssl pkcs12 -export -in "cert.pem" -inkey "key.pem" -out certificate.pfx -certfile "CA.cer"
I try using signtool
signtool sign /f "certificate.pfx" /p mypass /t http://timestamp.comodoca.com/authenticode "app.exe"
But I have the next error
SignTool Error: No certificates were found that met all the given criteria.
Reference
Signing .exe with .cer file (what is my certificate's name that signtool.exe is asking for?)

Powershell doesn't recognize openssl even after I added it to the system path

I am on a 64bit Windows 10. I installed Win64 OpenSSL v1.1.0f and added the install directory C:\OpenSSL-Win64\bin to my system PATH.
Upon running it in cmd or Powershell, I get:
openssl : The term 'openssl' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.
What else am I missing?
If you're running it in Powershell, check $env:path to be sure "C:\OpenSSL-Win64\bin" is in there. Previous comments all reference the PATH variable in in cmd.exe, which your error message suggests you are not using.
If it is not, run the following command in Powershell:
$env:path = $env:path + ";C:\OpenSSL-Win64\bin"
May be you need to close the session and open a new powershell, whenever you make changes to env variable it does not work on current session.

Not able to execute AWS Powershell tool cmdlet in TFS Post build script

I am trying to execute the few aws cmdlet command in post build script with TFS build. I have a AWS SDK tool is installed in build controller. I am able to run the same commands manually in Build controller. But when i invoke those commands in TFS post build script. It's giving me error that its not able to find the cmdlet installed on the build controller. I tried to change the execution policy but didn't help. I have an execution policy - bypass right now. script is executing but only the commands is not able to execute. I am thinking that it's issue because of something like Execution policy. Do we need to check anything else same like execution policy while we invoke any third party cmdlet from power shell.
Commands:
Set-AWSCredentials -AccessKey -SecretKey
Set-DefaultAWSRegion -Region us-east-1
Write-S3Object -BucketName agero-source-package -File "\\b tfadfa\adfa\adf\asdf\adsf\asdf\asd\xyz.zip"
Error:
Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:41 char:26
+ cd "\\b-tfsbc001wv\C$" | Set-DefaultAWSRegion -Region us-east-1
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-DefaultAWSRegion:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Write-S3Object : The term 'Write-S3Object' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At \\b-tfsbc001wv\c$\MV\BuildETA-API.ps1:43 char:26
+ cd "\\b-tfsbc001wv\c$" | Write-S3Object -BucketName agero-source-package -File " ...
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-S3Object:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
From the error messages, it would appear that the AWSPowerShell module cannot be found/automatically loaded by whatever account the TFS build process is running as.
Check that the module is installed to a globally available location under which the version of PowerShell you have searches for modules or, that the path to the module folder is present in the $PSModulePath environment variable for the TFS build account.
I got the same error on my TFS Build Agent:
Set-DefaultAWSRegion : The term 'Set-DefaultAWSRegion' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
After I installed AWS Command Line Interface x64 bit (AWSCLI64) I was able to set the Set-DefaultAWSRegion by stepping over the line of code.
I was getting this error until I ran Powershell using "Run as Administrator." So the problem might be with permissions.

Windows PowerShell cannot recognize sqlite3

I have installed SQLite3 on my computer in G:\SQLite3\sqlite3.exe
However, when I type "sqlite3" (no quotes) to PowerShell, it gives me the following error:
sqlite3 : The term 'sqlite3' is not recognized as the name of a cmdlet, functio
n, script file, or operable program. Check the spelling of the name, or if a pa
th was included, verify that the path is correct and try again.
At line:1 char:1
+ sqlite3
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (sqlite3:String) [], CommandNotF
oundException
+ FullyQualifiedErrorId : CommandNotFoundException
My Environmental Path includes G:\SQLite3, so when I run sqlite3 in command prompt (cmd.exe), it runs just fine. I prefer PowerShell though, so I would be glad, if someone could point me in the right direction how to make it accept this command. If that matters, I use Windows 8.
Most likely the directory G:\SQLite3 is not in your PATH environment variable, so PowerShell doesn't know where to look for the executable. Either run the executable with its full path, or add the directory to the $env:PATH:
$env:PATH += ';G:\SQLite3'
& sqlite3.exe