Error Getting Certificate using Get-Certificate

I have a server (Srv2.reskit.net) which I want to get a cert for. I can easily use the cert wizard in the IIS manager and it works perfectly. But I want to use PowerShell to get the cert and so tried to use Get-Certificate like this:

Get-Certificate -Template WebServer -CertStoreLocation Cert:\LocalMachine\My -SubjectName Srv2.reskit.org

This returns:

CertEntoll::CX500DistinguishedName::Encode: The string contains an invalid x500 name attributekei, oid, value, or delimiter

Any clues?

What I need is a working solution that gets the cert using only PowerShell - please do not offer solutions that make use of the GUI in any wa

July 6th, 2015 2:32pm

Start here:

PS C:\scripts> Import-Module Web*
PS C:\scripts> $iis=Dir iis:sslbindings
\PS C:\scripts> $iis[1].Store
MY
PS C:\scripts> $iis[1].ThumbPrint
4B1754E2AB3CFDFA085BEBF8FAA3C9FCE85F2A0F
PS C:\scripts>

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 4:14pm

Thomas,

The error code is saying that your Subjectname has an invalid character for the expected x500 formatting. Try using -DNSName instead.

Get-Certificate -Template WebServer -CertStoreLocation Cert:\LocalMachine\My -DNSName Srv2.reskit.org



July 6th, 2015 4:25pm

Start here:

PS C:\scripts> Import-Module Web*
PS C:\scripts> $iis=Dir iis:sslbindings
\PS C:\scripts> $iis[1].Store
MY
PS C:\scripts> $iis[1].ThumbPrint
4B1754E2AB3CFDFA085BEBF8FAA3C9FCE85F2A0F
PS C:\scripts>

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 5:17pm

You use the thumbprint and store name to get the matching certificate.

Your initial code does not get a cert it is used to request a new cert using a template.

PS C:\scripts> $cert=Get-Item cert:\LocalMachine\My\026AF812C3D06F7E1030345264912696C1E971C5
PS C:\scripts> $cert|select *

July 6th, 2015 5:20pm

Excellent - well at one level! :-)

I tried this:

Get-Certificate -Template WebServer -CertStoreLocation cert:\LocalMachine\My -DNSName 'Srv2.Reskit.Org'

It no longer gave the X500 name issue error, but now I get:

Get-Certificate: You do not have permission to request this type of certificate.: The permissions on the certificate template do not allow the current user to enroll for this type of certificate

This is being run as administrator (Enterprise Admin).

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 5:22pm

Excellent - well at one level! :-)

I tried this:

Get-Certificate -Template WebServer -CertStoreLocation cert:\LocalMachine\My -DNSName 'Srv2.Reskit.Org'

It no longer gave the X500 name issue error, but now I get:

Get-Certificate: You do not have permission to request this type of certificate.: The permissions on the certificate template do not allow the current user to enroll for this type of certificate

This is being run as administrator (Enterprise Admin).

July 6th, 2015 5:24pm

As the original post stated, I am trying to get a certificate from a Certificate Authority (I have a CA on another server) so that I can then use it for SSL to secure PSWA.

I know how to set the SSL bindings and to associate the right thumbprint     to point to the correct certificate.

What I am thus far unable to do is to write a PowerShell script that gets that certificate. I can do this using the IIS manager, but want an automation solution, preferably using PowerShell.

As explained in another post in this thread, I've fixed the original problem but still can not automate getting the cert.

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 5:29pm

Getting a certificate from a webserver is not the same as requesting a new certificate from a template.

You do not have permission to request certificates of the type you are requesting.  Have the CA grant you permission to request that kind of cert.

use explicit credentials in the re

July 6th, 2015 5:32pm

Getting a certificate from a webserver is not the same as requesting a new certificate from a template.

You do not have permission to request certificates of the type you are requesting.  Have the CA grant you permission to request that kind of

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 5:35pm

You are assuming that the CA has already granted you permission.  You are also assuming that the permission for the "WebServer" template has been granted.  Is there a template called "WebServer".  I am pretty sure the default SSL certificate template is called "SSLWebServer" but you can define any names you want for your templates.

Here is the example that most closely matches your reuiremetns:

PS C:\> $enrollResult = Get-Certificate -Template SslWebServer -DnsName www.contoso.com-Url https://www.contoso.com/policy/service.svc-Credential $cert -CertStoreLocation cert:\LocalMachine\My

July 6th, 2015 5:42pm

I have a 2012 R2 enterprise CA setup in a default setup, so yes, I assumed that I could use it go get a cert. And I CAN get a cert using the GUI on a separate domain joined server, so yes, I assume I have the permissions. 

I  also tried to get a cert for SSLWebServer, but as expected I get an error 'The requested certificate Template is not supported by this CA'. That error does not occur using  WebServer template. Running CertUtil.exe -Template or CertUtil -CATemplates show WebServer and not SSLWebServer.

In this case, the example in the help text you quoted appears to be incorrect.

I also tried adding a credential, but that just gives an empty error message.

Have you tested the suggestions you are making?

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 5:59pm

I cannot test you environment but I can suggest that you post in the Cert Server  forum as they will have more information on how to analyze you issues.

July 6th, 2015 6:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics