Skip to content

Instantly share code, notes, and snippets.

@chilversc
Created May 27, 2011 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilversc/995589 to your computer and use it in GitHub Desktop.
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
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()
@akshatakrao
Copy link

The piece of code threw an error :(Exception setting "SSLCertHash": "Exception from HRESULT: 0x8000500C"
At line:12 char:7

  • $site. <<<< SSLCertHash = Convert-ToCertificateHash 'f6208d753c985b1b32c0d02fd9ffcb1b52ca0115'
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : PropertyAssignmentException

Could you please help me out?

@chilversc
Copy link
Author

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