Hello, I'm trying to automate the creation of the SSL certificate in the iis server i wrote a powershell that do this but i m getting this error :
Line |
1 | Import-Module -Name WebAdministration -Force -SkipEditionCheck
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation,
| Version=7.4.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
InvalidOperation: D:\Venafi\installpfx.ps1:21
Line |
21 | $binding.AddSslCertificate($thumbprint, "My")
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Method invocation failed because
| [Deserialized.Microsoft.IIs.PowerShell.Framework.ConfigurationElement#bindings#binding] does not contain a
| method named 'AddSslCertificate'.
Restart-WebItem: A parameter cannot be found that matches parameter name 'Name'.
this is my powershell script :
Import-Module -Name WebAdministration -Force -SkipEditionCheck
$CertificatePassword = mymdp
$CertificateName = mycertname
$ServerName = myservername
$SiteName = mysitename
# Import PFX certificate
$certPassword = ConvertTo-SecureString -String $CertificatePassword -Force -AsPlainText
$cert = Import-PfxCertificate -FilePath "C:\$CertificateName.pfx" -CertStoreLocation Cert:\LocalMachine\My -Password $certPassword
# Get the Thumbprint of the imported certificate
$thumbprint = $cert.Thumbprint
# Create a new HTTPS binding for the website
New-WebBinding -Name $SiteName -IP "*" -Port 443 -Protocol https
# Set the certificate for use in the HTTPS binding
$binding = Get-WebBinding -Name $SiteName -Protocol https
if ($binding) {
$binding.AddSslCertificate($thumbprint, "My")
# Restart the website to apply the changes
Restart-WebItem -Name $SiteName
} else {
Write-Host "The website '$SiteName' does not exist in IIS or there was an issue with creating the HTTPS binding."
}