@@ -2,20 +2,31 @@ $ErrorActionPreference = "Stop"
2
2
3
3
Import-Module BitsTransfer
4
4
5
+ $opensslPath = " $ENV: HOMEDRIVE \OpenSSL-Win32"
6
+
5
7
if ($PSVersionTable.PSVersion.Major -lt 4 ) {
6
8
$scriptPath = split-path - parent $MyInvocation.MyCommand.Definition
7
9
. " $scriptPath \GetFileHash.ps1"
8
10
}
9
11
10
- $opensslPath = " $ENV: HOMEDRIVE \OpenSSL-Win32"
11
-
12
12
function VerifyHash ($filename , $expectedHash ) {
13
13
$hash = (Get-FileHash - Algorithm SHA1 $filename ).Hash
14
14
if ($hash -ne $expectedHash ) {
15
15
throw " SHA1 hash not valid for file: $filename . Expected: $expectedHash Current: $hash "
16
16
}
17
17
}
18
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
+
19
30
function InstallOpenSSL () {
20
31
if (! (Test-Path $opensslPath )) {
21
32
$filename = " Win32OpenSSL_Light-1_0_1i.exe"
@@ -77,7 +88,7 @@ function ImportCertificate($certFilePfx, $pfxPassword) {
77
88
}
78
89
79
90
function RemoveExistingWinRMHttpsListener () {
80
- $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" } }
81
92
if ($httpsListener ) {
82
93
Remove-Item - Recurse - Force - Path (" wsman:\localhost\listener\" + $httpsListener.Name )
83
94
}
@@ -91,6 +102,11 @@ function CreateWinRMHttpsFirewallRule() {
91
102
$certFilePfx = " server_cert.p12"
92
103
$pfxPassword = " Passw0rd"
93
104
105
+ $osVer = [System.Environment ]::OSVersion.Version
106
+ if ($osVer.Major -eq 6 -and $osVer.Minor -le 1 ) {
107
+ InstallVCRedist2008
108
+ }
109
+
94
110
InstallOpenSSL
95
111
96
112
GenerateSelfSignedCertificate $certFilePfx $pfxPassword
@@ -104,6 +120,8 @@ RemoveExistingWinRMHttpsListener
104
120
New-Item - Path wsman:\localhost\listener - transport https - address * - CertificateThumbPrint $certThumbprint - Force
105
121
106
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
107
125
108
126
CreateWinRMHttpsFirewallRule
109
127
0 commit comments