Before, blabbing on about tonight’s topic, I wanted to share something very special. My good friend Monil sent me a really funny picture of his little girl playing with my Windows PowerShell Unleashed book. Apparently, the book has become her new favorite play thing. So, I guess PowerShell has gotten so popular that it is now replacing the Baby Einstein videos. Talk about starting them early! [url=http://www.flickr.com/photos/10233132@N05/1200422380/][img]http://farm2.static.flickr.com/1376/1200422380_fb80360f49_m.jpg[/img][/url] ***Disclaimer, actually she likes the book because it is red*** Moving on… Tonight, I wanted to post a little quick and dirty script that I whipped up to complete a certificate request using PowerShell and certreq.exe. The details for what the script does are as follows:
- It takes in a user’s UID and email address using the read-host cmdlet (ideally an enrollment agent would be running this script).
- Using that information the script then generates an INF file that can be used by certreq.exe.
- Next, using that INF file the script then uses certreq.exe to generate and complete a certificate request to an online issuing CA that is hosting a particular certificate template.
[string]$TemplateName = "ABCUserAuthentication"
[string]$CAName = "pkica01.abc.comABC INC Class 2 Low Assurance CA 01"
[string]$UID = read-host "Please enter the UID"
[string]$Email = read-host "Please enter the user's Email Address"
###################################
# Generate Request File
###################################
write-host
write-host "Generating Request File" -ForegroundColor Yellow
remove-item .supusercert.inf -ErrorAction silentlycontinue
remove-item .supusercert.req -ErrorAction silentlycontinue
add-content .supusercert.inf "[NewRequest]`r
Subject = `"CN=$UID`"`r
Exportable = TRUE`r
RequestType = CMC`r
[RequestAttributes]`r
CertificateTemplate = `"$TemplateName`"`r
SAN = `"Email=$Email`""
.certreq -new .usercert.inf .usercert.req
###################################
# Send Request
###################################
write-host "Sending Certificate Request" -ForegroundColor Yellow
.certreq -submit -config "$CAName" .supusercert.req .$UID.cer
###################################
# Install Certificate
###################################
write-host "Installing Certificate" -ForegroundColor Yellow
.certreq -accept .$UID.cer
For all of today's Microsoft news, visit the Microsoft Subnet.



