Skip to content

Commit d0a5352

Browse files
committed
Adds 2008 R2 support in WinRM setup script
1 parent c6ba389 commit d0a5352

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

SetupWinRMAccessSelfSigned.ps1

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@ $ErrorActionPreference = "Stop"
22

33
Import-Module BitsTransfer
44

5+
$opensslPath = "$ENV:HOMEDRIVE\OpenSSL-Win32"
6+
57
if($PSVersionTable.PSVersion.Major -lt 4) {
68
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
79
. "$scriptPath\GetFileHash.ps1"
810
}
911

10-
$opensslPath = "$ENV:HOMEDRIVE\OpenSSL-Win32"
11-
1212
function VerifyHash($filename, $expectedHash) {
1313
$hash = (Get-FileHash -Algorithm SHA1 $filename).Hash
1414
if ($hash -ne $expectedHash) {
1515
throw "SHA1 hash not valid for file: $filename. Expected: $expectedHash Current: $hash"
1616
}
1717
}
1818

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+
1930
function InstallOpenSSL() {
2031
if (!(Test-Path $opensslPath)) {
2132
$filename = "Win32OpenSSL_Light-1_0_1i.exe"
@@ -77,7 +88,7 @@ function ImportCertificate($certFilePfx, $pfxPassword) {
7788
}
7889

7990
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"} }
8192
if ($httpsListener) {
8293
Remove-Item -Recurse -Force -Path ("wsman:\localhost\listener\" + $httpsListener.Name)
8394
}
@@ -91,6 +102,11 @@ function CreateWinRMHttpsFirewallRule() {
91102
$certFilePfx = "server_cert.p12"
92103
$pfxPassword = "Passw0rd"
93104

105+
$osVer = [System.Environment]::OSVersion.Version
106+
if ($osVer.Major -eq 6 -and $osVer.Minor -le 1) {
107+
InstallVCRedist2008
108+
}
109+
94110
InstallOpenSSL
95111

96112
GenerateSelfSignedCertificate $certFilePfx $pfxPassword
@@ -104,6 +120,8 @@ RemoveExistingWinRMHttpsListener
104120
New-Item -Path wsman:\localhost\listener -transport https -address * -CertificateThumbPrint $certThumbprint -Force
105121

106122
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
107125

108126
CreateWinRMHttpsFirewallRule
109127

0 commit comments

Comments
 (0)