It has been a while since I have been on here.
I have 300 new servers in my environment that my organization wants to generate certificates for using "OpenSSL". I have the names of the systems, and I have used OpenssL before to do this, thing is, im not trying to sit around all day entering each piece of information over and over 300 times. I want to automate this. So far, everything works until I have to enter the information for the State, Common Name, Locality, Org, etc.
My question is, using Powershell; How can I feed this information into Openssl?
FYI, I have spent the last two days searching the internet. I constantly come across bash scripts, Openssl manuals, "how to's" (with no automation) for generating certificates, especially using powershell.
I did come across one result where the person used a function, but it all it did was generate ONE request, not multiple, and he didn't enter any information AT ALL. But he ended up with a CSR so I'm confused how that worked exactly.
Here is my current code, I have cleaned it to maintain privacy:
$ServerList = 'C:\Temp\server_names.txt' #This is the input file with the server names. It is all clean and only contains the names. Not FQDNs.
$ServerlistContent = get-content $ServerList #Dump the contents of the input file into a variable
$keyPath = "D:\Openssl\OpenSSL-Win64\bin\Servers\Key\" #Output path for the '.key' file to be generated
$PemPath = "D:\Openssl\OpenSSL-Win64\bin\Servers\Pem\" #Output path for the '.pem' file to be generated
$FQDN = '.contoso.com' #Part of the common name, this will be concatenated before being used.
#Entries below this point are meant to be used when entering the information needed to generate the Certificate
$Conutry_Name = 'US'
$State_Name = ''
$Locality_Name = ''
$Org_Name = 'Contoso'
$Org_Unit_Name = 'HR'
$Email_Address = ''
$Challenge_pwd = ''
$optional_Name = ''
#Entries Above this point are meant to be used when entering the information needed to generate the Certificate
#Begin looping through the variable "$ServerlistContent" so that this Can be automated
foreach ($server in $ServerlistContent) {
$Commonname = $server + $FQDN #Entry to be used for generating the certificate request.
$Serverkey = $Server + ".key"
$key_out = $keypath + $serverkey #Used to Create the path needed (to include the server name and file extension) for the Openssl Command
$Serverpem = $Server + "_req.pem"
$Pem_out = $PemPath + $Serverpem #Used to Create the path needed (to include the server name and file extension) for the Openssl Command
D:\Openssl\OpenSSL-Win64\bin\\openssl.exe genrsa -out $key_out 2048
D:\Openssl\OpenSSL-Win64\bin\\openssl.exe req -new -key $key_out -sha256 -out $Pem_out -verify -newhdr
}
#After this point, here is where I run into trouble, Powershell just hangs and i cannot enter anything, not even manually. (See Image 1)
Image 1:
