From e97f77a804dc81a52a3fb6efe21786dc3c421450 Mon Sep 17 00:00:00 2001 From: Dawid Ciecierski Date: Wed, 23 Jan 2019 14:50:53 +0100 Subject: [PATCH] Use tested and expanded path Allows use of filename in current working dir instead of only full path required by X509Certificate2 'ctor. --- ssl-windows/Convert-PfxToPem.ps1 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ssl-windows/Convert-PfxToPem.ps1 b/ssl-windows/Convert-PfxToPem.ps1 index ee3a371a..783f0977 100644 --- a/ssl-windows/Convert-PfxToPem.ps1 +++ b/ssl-windows/Convert-PfxToPem.ps1 @@ -169,7 +169,25 @@ Add-Type @' '@ try { - if (-not ($cert = New-Object Security.Cryptography.X509Certificates.X509Certificate2($PFXFile, $Passphrase, 'Exportable'))) + if (Test-Path -Path $PFXFile -PathType Leaf) + { + $pfxPath = (Get-Item -Path $PFXFile).FullName + } + else + { + Write-Warning "Unable to find PFX file $PFXFile" + Exit + } +} +catch +{ + Write-Warning "Unable to acces PFX file $PFXFile" + Exit +} + +try +{ + if (-not ($cert = New-Object Security.Cryptography.X509Certificates.X509Certificate2($pfxPath, $Passphrase, 'Exportable'))) { Write-Warning "Unable to load certificate $PFXFile" Exit