Repository navigation
Expand file tree
/
Copy pathwebserver.ps1
More file actions
88 lines (78 loc) · 2.72 KB
/
Copy pathwebserver.ps1
File metadata and controls
88 lines (78 loc) · 2.72 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#set up vm
#set up IIS
function Install-PowerLabWebServer {
param(
[Parameter(Mandatory)]
[string]$ComputerName,
[Parameter(Mandatory)]
[pscredential]$DomainCredential
)
$session = New-PSSession -VMName $ComputerName -Credential $DomainCredential
Invoke-Command -Session $session -ScriptBlock {
Add-WindowsFeature -Name 'Web-Server'
}
Remove-PSSession $session
}
#installation/setup
Install-PowerLabWebServer -ComputerName $Name -DomainCredential $DomainCredential
#working, import webadministration module
$session = New-PSSession -VMName Web-Server -Credential (Import-Clixml -Path C:\)
Enter-PSSession -Session $session
Import-Module webadministration
#Websites
Get-Website -Name 'Default Web Site' | remove-website
#new
New-website -Name Powershell -physicalpath C:\
#apps pool
#config certificate
function New-IISCertificate {
param(
[Parameter(Mandatory)]
[string]$WebServerName,
[Parameter(Mandatory)]
[SecureString]$PrivateKeyPassword,
[Parameter()]
[string]$CertificateSubject = 'PowerShellForSysAdmins',
[Parameter()]
[string]$PublicKeyLocalPath = 'C:\PublicKey.cer',
[Parameter()]
[string]$PrivateKeyLocalPath = 'C:\PrivateKey.pfx',
[Parameter()]
[string]$CertificateStore = 'Cert:\LocalMachine\My'
)
# Generate a new self-signed certificate
$cert = New-SelfSignedCertificate `
-DnsName $WebServerName `
-CertStoreLocation $CertificateStore `
-Subject $CertificateSubject `
-FriendlyName $CertificateSubject `
-KeyExportPolicy Exportable `
-KeyAlgorithm RSA `
-HashAlgorithm SHA256 `
-KeyLength 2048 `
-NotAfter (Get-Date).AddYears(5) `
-Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" `
-KeyUsage DigitalSignature,KeyEncipherment `
-Type SSLServerAuthentication
# Export the public and private keys to files
$pwd = ConvertTo-SecureString -String $PrivateKeyPassword -Force -AsPlainText
Export-Certificate `
-Cert $cert `
-FilePath $PublicKeyLocalPath
Export-PfxCertificate `
-Cert $cert `
-FilePath $PrivateKeyLocalPath `
-Password $pwd
# Display information about the certificate
$cert | Format-List *
# Install the certificate in the certificate store
$certThumbprint = $cert.Thumbprint
$certPath = "Cert:\LocalMachine\My\" + $certThumbprint
Import-PfxCertificate `
-FilePath $PrivateKeyLocalPath `
-CertStoreLocation $CertificateStore `
-Password $pwd `
-Exportable:$true `
-CertFriendlyName $CertificateSubject `
-ErrorAction Stop
}