-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-IISExpressCert.ps1
More file actions
68 lines (49 loc) · 1.83 KB
/
Copy pathCreate-IISExpressCert.ps1
File metadata and controls
68 lines (49 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<#
.SYNOPSIS
Create IIS Express Development Certificate
.DESCRIPTION
Create a self-signed certificate for IIS Express development
.EXAMPLE
PS > Create-IISExpressCert.ps1
Creates a new self-signed certificate for IIS Express development
.EXAMPLE
PS > Create-IISExpressCert.ps1 -FriendlyName "MyDevCert"
Creates a new self-signed certificate for IIS Express development with the specified friendly name
.LINK
http://github.com/vrhovnik
#>
$friendlyName = "IIS Express Development Certificate"
$certStore = "Cert:\LocalMachine\My"
$oldCert = Get-ChildItem $certStore | Where-Object FriendlyName -match $friendlyName
if(-not $oldCert) {
Write-Host "$friendlyName certificate not found"
return
}
Write-Host "Removing $($oldCert.Thumbprint) certificate"
Remove-Item -Path $oldCert.PSPath -Confirm:$false
Write-Host "Creating $friendlyName certificate"
$selfSignedCertParam = @{
Subject = "localhost"
DnsName = "localhost"
KeyAlgorithm = "RSA"
KeyLength = 2048
NotBefore = (Get-Date)
NotAfter = (Get-Date).AddYears(5)
CertStoreLocation = $certStore
FriendlyName = $friendlyName
HashAlgorithm = "SHA256"
KeyUsage = "DigitalSignature", "KeyEncipherment", "DataEncipherment"
TextExtension = @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
}
$cert = New-SelfSignedCertificate @selfSignedCertParam
# The app ID is the IIS Express app ID
$certThumbprint = $cert.Thumbprint
$appId = "{214124cd-d05b-4309-9af9-9caa44b2b74a}"
$startPort = 44300
$endPort = 44399
Write-Host "Binding ${certThumbprint} certificate using netsh port=${startPort}:${endPort} and appID=${appId}"
$startPort..$endPort | ForEach-Object {
$port = $_
cmd /c "netsh http delete sslcert ipport=0.0.0.0:$port > nul 2>&1"
cmd /c "netsh http add sslcert ipport=0.0.0.0:$port certhash=$certThumbprint appid=$appId certstorename=MY > nul 2>&1"
}