Created
May 27, 2011 16:11
-
-
Save chilversc/995589 to your computer and use it in GitHub Desktop.
Converts a certificate thumbprint to a string suitable for IIS' adsi SSLCertHash property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Convert-ToCertificateHash($HashString) { | |
$pairs = @([regex]::Matches($HashString, '..') | ForEach-Object { $_.Value }) | |
-join @( | |
for ($x=0; $x -lt $pairs.Length; $x += 2) { | |
$a, $b = $pairs[$x..($x+1)] | |
[char] [uint16]::Parse(-join ($b, $a), 'hexnumber') | |
} | |
) | |
} | |
$id = ... | |
$site = [adsi] 'IIS://localhost/W3SVC/$id' | |
$site.SSLCertHash = Convert-ToCertificateHash 'f6208d753c985b1b32c0d02fd9ffcb1b52ca0115' | |
$site.SetInfo() |
This only applies to IIS 6, if you're using IIS 7 then you want to look at the newer powershell commands, or web.config settings
http://learn.iis.net/page.aspx/491/powershell-snap-in-configuring-ssl-with-the-iis-powershell-snap-in/
http://technet.microsoft.com/en-us/library/ee790599.aspx
http://learn.iis.net/page.aspx/144/how-to-set-up-ssl-on-iis/
Enabling IIS 6 metabase compatibility with IIS 7 (not the preferred option)
http://learn.iis.net/page.aspx/125/metabase-compatibility-with-iis-7-and-above/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The piece of code threw an error :(Exception setting "SSLCertHash": "Exception from HRESULT: 0x8000500C"
At line:12 char:7
Could you please help me out?