securitypowershellcertificatex509certificatex509

Powershell and System.Security.Cryptography.X509Certificates.X509Certificate2


i'm getting this error when i run the system.security namespace. This is what i am running after

$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")

New-Object: Cannot find type [System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")]: make sure the assembly containing this type is loaded. 
At line:1 char:19
    + $cert = New-Object <<<<
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand**

What am i doing wrong?


Solution

  • I've solved my problem. It's easily:

    cd\
    $cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\mycert.cer")
    

    cd\ is necessary