PoshCode Archive  Artifact [45691779fa]

Artifact 45691779fac2fea1f1775fe65f4a6c56a724bd17bf0fd4568f36c486c39d51ea:

  • File Add-SSL-Cert-to-IIS.ps1 — part of check-in [41e711ef82] at 2018-06-10 14:18:42 on branch trunk — How to add a SSL Certificate to IIS with Powershell as well as set the SSL Binding for the site that’s using the certificate. (user: Brian H Madsen size: 861)

# encoding: ascii
# api: powershell
# title: Add SSL Cert to IIS
# description: How to add a SSL Certificate to IIS with Powershell as well as set the SSL Binding for the site that’s using the certificate.
# version: 0.1
# type: function
# author: Brian H Madsen
# license: CC0
# function: Add-SSLCertificate
# x-poshcode-id: 6634
# x-archived: 2017-03-15T06:38:37
# x-published: 2017-11-25T19:48:00
#
# This uses a PFX certificate file.
#
function Add-SSLCertificate{
    param([string]$pfxPath,[string]$pfxPassword,[string]$hostHeader,[string]$siteName)

    $certMgr = New-Object -ComObject IIS.CertObj -ErrorAction SilentlyContinue    
    $certMgr.ImportToCertStore($pfxPath,$pfxPassword,$true,$true)

    Import-Module WebAdministration;
    New-WebBinding -Name $siteName -Port 443 -Protocol https -HostHeader $hostHeader    
}