| Server IP : 185.208.173.17 / Your IP : 87.236.161.98 Web Server : Microsoft-IIS/10.0 System : Windows NT SRV8576125506 10.0 build 26100 (Windows Server 2016) AMD64 User : IUSR ( 0) PHP Version : 7.4.13 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Windows/System32/WindowsPowerShell/v1.0/Modules/Carbon/Certificates/ |
Upload File : |
# Copyright 2012 Aaron Jensen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function Set-SslCertificateBinding
{
<#
.SYNOPSIS
Sets an SSL certificate binding for a given IP/port.
.DESCRIPTION
Uses the netsh command line application to set the certificate for an IP address and port. If a binding already exists for the IP/port, it is removed, and the new binding is created. No validation is performed on the thumbprint.
.EXAMPLE
Set-SslCertificateBinding -IPAddress 43.27.89.54 -Port 443 -ApplicationID 88d1f8da-aeb5-40a2-a5e5-0e6107825df7 -Thumbprint 478907345890734590743
Configures the computer to use the 478907345890734590743 certificate on IP 43.27.89.54, port 443.
.EXAMPLE
Set-SslCertificateBinding -ApplicationID 88d1f8da-aeb5-40a2-a5e5-0e6107825df7 -Thumbprint 478907345890734590743
Configures the compute to use the 478907345890734590743 certificate as the default certificate on all IP addresses, port 443.
#>
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[IPAddress]
# The IP address for the binding. Defaults to all IP addresses.
$IPAddress = '0.0.0.0',
[UInt16]
# The port for the binding. Defaults to 443.
$Port = 443,
[Parameter(Mandatory=$true)]
[Guid]
# A unique ID representing the application using the binding. Create your own.
$ApplicationID,
[Parameter(Mandatory=$true)]
[string]
# The thumbprint of the certificate to use. The certificate must be installed.
$Thumbprint
)
$commonParams = @{ }
if( $pscmdlet.BoundParameters.WhatIf )
{
$commonParams.WhatIf = $true
}
if( $IPAddress.AddressFamily -eq [Net.Sockets.AddressFamily]::InterNetworkV6 )
{
$ipPort = '[{0}]:{1}' -f $IPAddress,$Port
}
else
{
$ipPort = '{0}:{1}' -f $IPAddress,$Port
}
Remove-SslCertificateBinding -IPAddress $IPAddress -Port $Port @commonParams
if( $pscmdlet.ShouldProcess( $IPPort, 'creating SSL certificate binding' ) )
{
Write-Host "Creating SSL certificate binding for $IPPort with certificate $Thumbprint."
netsh http add sslcert ipport=$ipPort "certhash=$($Thumbprint)" "appid={$ApplicationID}"
}
}