powershell - Determine if a .pfx file needs a password before calling Add-AzureCertificate -


i using following code install .pfx file on azure cloud service:

add-azurecertificate -servicename $cloudservicename -certtodeploy $pfxfile.fullname -erroraction 'stop' -password $applicationcertspassword 

i think it's throwing exception because of .pfx file not require password.

how can determine before hand whether or not .pfx file requires password?

edit: i'd determine before hand if .pfx file has password or not can avoid running commandlet again without password argument in catch block.

you put in try{} , same command without password in catch{}, that's kind of dirty scripting.

try{     add-azurecertificate -servicename $cloudservicename -certtodeploy $pfxfile.fullname -erroraction 'stop' -password $applicationcertspassword } catch{     add-azurecertificate -servicename $cloudservicename -certtodeploy $pfxfile.fullname -erroraction 'stop' } 

what think instead attempt load certificate object no password, , if fails i'd know there's password it.

$oldea = $erroractionpreference $erroractionpreference = silentlycontinue if([system.security.cryptography.x509certificates.x509certificate2]::createfromcertfile($pfxfile.fullname)){"no password"} $erroractionpreference = $oldea 

pretty sure that'll accomplish want. don't happen have pfx file without password verify right though, because jan pointed out aren't should have in general.


Popular posts from this blog

html/hta mutiple file in audio player -

debugging - Reference - What does this error mean in PHP? -