ebekker / ACMESharp

An ACME client library and PowerShell client for the .NET platform (Let's Encrypt)
https://pkisharp.github.io/ACMESharp-docs/
1.21k stars 185 forks source link

Get-ACMECertificate -ExportPkcs12 does not work with relative paths #350

Closed murdockcrc closed 5 years ago

murdockcrc commented 6 years ago

I have tried to pass the following values to the ExportLkcs12 to save the PFX in the directory where the script is running:

./cert.pfx .\cert.pfx

The command does not fail with an error but the PFX is never generated.

If I pass an absolute file path, the operations works.

I'm not sure if I am doing something wrong with the syntax for the relative path, so perhaps the issue is on my side. Please comment if you know how to achieve this with the Get-ACMECertificate command.

ebekker commented 5 years ago

There is a bit of an issue in general with paths in PWSH when crossing over the boundary between the runspace context and manage code. When using relative paths and you are referring to a path relative to your current directory in a PowerShell session, instead of referring to current as ./, I recommend using $PWD/.

The $PWD built-in variable always evaluates to the current path in the current PWSH session. (Note, however, this may also evaluate to a non-disk path, such as a registry or cert store or whatever, if that's what your current path is.)

In your example, using

$PWD/cert.pfx
## --or--
$PWD\cert.pfx

should work just fine.