11$ErrorActionPreference = " Stop"
22
3+ Import-Module BitsTransfer
4+
35$opensslPath = " $ENV: HOMEDRIVE \OpenSSL-Win32"
46
7+ if ($PSVersionTable.PSVersion.Major -lt 4 ) {
8+ $scriptPath = split-path - parent $MyInvocation.MyCommand.Definition
9+ . " $scriptPath \GetFileHash.ps1"
10+ }
11+
512function VerifyHash ($filename , $expectedHash ) {
613 $hash = (Get-FileHash - Algorithm SHA1 $filename ).Hash
714 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 "
916 }
1017}
1118
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+
1230function InstallOpenSSL () {
1331 if (! (Test-Path $opensslPath )) {
1432 $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
1634
17- VerifyHash $filename " 303A6010192161C3BA103978DD4D6932CA9340DC "
35+ VerifyHash $filename " 439BA19F18803432E39F0056209B010A63B96644 "
1836
1937 Start-Process - Wait - FilePath $filename - ArgumentList " /silent /verysilent /sp- /suppressmsgboxes"
2038 del $filename
@@ -70,7 +88,7 @@ function ImportCertificate($certFilePfx, $pfxPassword) {
7088}
7189
7290function 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" } }
7492 if ($httpsListener ) {
7593 Remove-Item - Recurse - Force - Path (" wsman:\localhost\listener\" + $httpsListener.Name )
7694 }
@@ -84,6 +102,11 @@ function CreateWinRMHttpsFirewallRule() {
84102$certFilePfx = " server_cert.p12"
85103$pfxPassword = " Passw0rd"
86104
105+ $osVer = [System.Environment ]::OSVersion.Version
106+ if ($osVer.Major -eq 6 -and $osVer.Minor -le 1 ) {
107+ InstallVCRedist2008
108+ }
109+
87110InstallOpenSSL
88111
89112GenerateSelfSignedCertificate $certFilePfx $pfxPassword
@@ -97,6 +120,8 @@ RemoveExistingWinRMHttpsListener
97120New-Item - Path wsman:\localhost\listener - transport https - address * - CertificateThumbPrint $certThumbprint - Force
98121
99122Set-Item wsman:\localhost\service\Auth\Basic - Value $true
123+ # Increase the timeout for long running scripts
124+ Set-Item wsman:\localhost\MaxTimeoutms - Value 1800000
100125
101126CreateWinRMHttpsFirewallRule
102127
0 commit comments