Create certificate using SelfSSL7 tool

02/11/2012 10:41

#Create Certificate - use SelfSSL7 tool

#input parameters: $certificateName, $iisSiteName. SelfSSL7.exe must be copied to the script location.


$certificate=get-childitem -path cert:\LocalMachine\Root|where-object {$_.Subject -match $certificateName}
if($certificate -eq $null)
{

    write-host "Creating certificate..."
    #.\SELFSSL7.exe /Q /T /I /S "Chamdev7.Secure.fln.Local" /V 1000 /N cn=Chamdev7.Secure.fln.Local
    $exe=".\SELFSSL7.exe"
    $siteName=[string]::format("""{0}""", $iisSiteName)
    & $exe /Q /T /I /S $siteName /V 1000 /N cn=$certificateName

    #way to remove double binding (created by SelfSSL7.exe), no permissions using IIS: drive

    $serverManager = New-Object Microsoft.Web.Administration.ServerManager
    $site = $serverManager.Sites | where { $_.Name -eq $iisSiteName}
    $site.Bindings[0].delete()
    $serverManager.CommitChanges()

    #start running IIS site again
    (get-childitem "IIS:\sites"|where-object {$_.Name -eq $iisSiteName}).Start()
    write-host "Certificate created."
    iisreset
}