How to run AddSslCertificate in PowerShell to bind a new certificate

Charles Tang 45 Reputation points
2023-04-20T20:46:23.3833333+00:00

Try to use PowerShell script to bind a new certificate, but AddSslCertificate failed. Can you help?

Import-Module WebAdministration
$bindings = Get-WebBinding
Write-Host $bindings 

Get-WebBinding |
    Foreach-Object {
            $_.AddSslCertificate($newCert.Thumbprint,'My')
}
Got the following output with warning and error:

WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

https *:443:tax-direct-dc-test.aka.amazon.com sslFlags=1 https *:443:tax-direct-le-test.aka.amazon.com sslFlags=1 https *:443:tax-direct-wf-test.aka.amazon.com sslFlags=1

Line |
  26 |      Foreach-Object {
     |      ~~~~~~~~~~~~~~~~
     | Method invocation failed because
     | [Deserialized.Microsoft.IIs.PowerShell.Framework.ConfigurationElement#bindings#binding] does not contain a
     | method named 'AddSslCertificate'.
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,690 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,466 Reputation points
    2023-04-20T21:31:41.1133333+00:00

    Did you follow the suggestion in the "WARNING:" message?

    If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

    Deserialized objects don't have methods. They're text-only.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.