Appendix C: Create Failover Management Server Certificate script
# Run this script once for each management server for which a certificate is needed.
# Certificate should be executed on the single computer where the CA certificate is located.
# The created certificate should then be moved to the management servers and imported into the certificate store there.
# Load CA certificate from store (thumbprint must be in ca_thumbprint.txt)
$ca_thumbprint = Get-Content -Path "$PSScriptRoot\ca_thumbprint.txt"
$ca_certificate = (Get-ChildItem -Path cert:\CurrentUser\My\$ca_thumbprint)
# Prompt user for DNS names to include in certificate
$dnsNames = Read-Host 'DNS names for management server certificate (delimited by space - 1st entry is also subject of certificate)'
$dnsNamesArray = @($dnsNames -Split ' ' | foreach { $_.Trim() } | where { $_ })
if ($dnsNamesArray.Length -eq 0) {
Write-Host -ForegroundColor Red 'At least one DNS name should be specified'
exit
}
$dnsEntries = ($dnsNamesArray | foreach { "DNS=$_" }) -Join '&'
# Optionally allow the user to type in a list of IP addresses to put in the certificate
$ipAddresses = Read-Host 'IP addresses for management server certificate (delimited by space)'
$ipAddressesArray = @($ipAddresses -Split ' ' | foreach { $_.Trim() } | where { $_ })
if ($ipAddressesArray.Length -gt 0) {
$ipEntries = ($ipAddressesArray | foreach { "IPAddress=$_" }) -Join '&'
$dnsEntries = "$dnsEntries&$ipEntries"
}
$subjectName = $ipAddressesArray[0]
# Build final dns entries string (e.g. "2.5.29.17={text}DNS=myhost&DNS=myhost.domain.com&IPAddress=10.0.0.103")
$dnsEntries = "2.5.29.17={text}$dnsEntries"
# The only required purpose of the certificate is "Server Authentication"
$serverAuthentication = '2.5.29.37={critical}{text}1.3.6.1.5.5.7.3.1'
# Now - create the management server certificate
$certificate = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -Subject $subjectName -Signer $ca_certificate `
-FriendlyName 'VMS Server Certificate' -TextExtension @($dnsEntries, $serverAuthentication)
# Export certificate to disk - protect with a password
$password = Read-Host -AsSecureString "Management server certificate password"
Export-PfxCertificate -Cert "Cert:\CurrentUser\My\$($certificate.Thumbprint)" -FilePath "$PSScriptRoot\$subjectName.pfx" -Password $password
# Delete the management server certificate from the local certificate store
$certificate | Remove-Item