1
1
$ErrorActionPreference = " Stop"
2
2
3
+ Import-Module BitsTransfer
4
+
3
5
$opensslPath = " $ENV: HOMEDRIVE \OpenSSL-Win32"
4
6
7
+ if ($PSVersionTable.PSVersion.Major -lt 4 ) {
8
+ $scriptPath = split-path - parent $MyInvocation.MyCommand.Definition
9
+ . " $scriptPath \GetFileHash.ps1"
10
+ }
11
+
5
12
function VerifyHash ($filename , $expectedHash ) {
6
13
$hash = (Get-FileHash - Algorithm SHA1 $filename ).Hash
7
14
if ($hash -ne $expectedHash ) {
8
- throw " SHA1 hash not valid for file: $filename "
15
+ throw " SHA1 hash not valid for file: $filename . Expected: $expectedHash Current: $hash "
9
16
}
10
17
}
11
18
19
+ function InstallVCRedist2008 () {
20
+ $filename = " vcredist_x86_2008.exe"
21
+ $url = " http://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe"
22
+ Start-BitsTransfer - Source $url - Destination $filename
23
+
24
+ VerifyHash $filename " 56719288ab6514c07ac2088119d8a87056eeb94a"
25
+
26
+ Start-Process - Wait - FilePath $filename - ArgumentList " /q"
27
+ del $filename
28
+ }
29
+
12
30
function InstallOpenSSL () {
13
31
if (! (Test-Path $opensslPath )) {
14
32
$filename = " Win32OpenSSL_Light-1_0_1i.exe"
15
- Invoke-WebRequest - Uri " http://slproweb.com/download/$filename " - OutFile $filename
33
+ Start-BitsTransfer - Source " http://slproweb.com/download/$filename " - Destination $filename
16
34
17
- VerifyHash $filename " 303A6010192161C3BA103978DD4D6932CA9340DC "
35
+ VerifyHash $filename " 439BA19F18803432E39F0056209B010A63B96644 "
18
36
19
37
Start-Process - Wait - FilePath $filename - ArgumentList " /silent /verysilent /sp- /suppressmsgboxes"
20
38
del $filename
@@ -70,7 +88,7 @@ function ImportCertificate($certFilePfx, $pfxPassword) {
70
88
}
71
89
72
90
function RemoveExistingWinRMHttpsListener () {
73
- $httpsListener = Get-Item - Path wsman:\localhost\listener\* | where {$_.Keys.Contains ( " Transport=HTTPS" ) }
91
+ $httpsListener = Get-Item - Path wsman:\localhost\listener\* | where {$_.Keys | where { $_ -eq " Transport=HTTPS" } }
74
92
if ($httpsListener ) {
75
93
Remove-Item - Recurse - Force - Path (" wsman:\localhost\listener\" + $httpsListener.Name )
76
94
}
@@ -84,6 +102,11 @@ function CreateWinRMHttpsFirewallRule() {
84
102
$certFilePfx = " server_cert.p12"
85
103
$pfxPassword = " Passw0rd"
86
104
105
+ $osVer = [System.Environment ]::OSVersion.Version
106
+ if ($osVer.Major -eq 6 -and $osVer.Minor -le 1 ) {
107
+ InstallVCRedist2008
108
+ }
109
+
87
110
InstallOpenSSL
88
111
89
112
GenerateSelfSignedCertificate $certFilePfx $pfxPassword
@@ -97,6 +120,8 @@ RemoveExistingWinRMHttpsListener
97
120
New-Item - Path wsman:\localhost\listener - transport https - address * - CertificateThumbPrint $certThumbprint - Force
98
121
99
122
Set-Item wsman:\localhost\service\Auth\Basic - Value $true
123
+ # Increase the timeout for long running scripts
124
+ Set-Item wsman:\localhost\MaxTimeoutms - Value 1800000
100
125
101
126
CreateWinRMHttpsFirewallRule
102
127
0 commit comments