Skip to content

Commit b54535b

Browse files
committed
powershell: normalize aws and gcp setup winrm scripts
1 parent 69331f6 commit b54535b

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

scripts/aws/setup_winrm.txt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
11
<powershell>
2+
function Write-Log
3+
{
4+
Param (
5+
[Parameter(Mandatory = $True, Position = 1)][string]$Message,
6+
[string]$LogFile = "C:\provision\log.log"
7+
)
8+
9+
$LogDir = (split-path $LogFile -parent)
10+
If ((Test-Path $LogDir) -ne $True)
11+
{
12+
New-Item -Path $LogDir -ItemType Directory -Force
13+
}
14+
15+
$msg = "{0} {1}" -f (Get-Date -Format o), $Message
16+
Add-Content -Path $LogFile -Value $msg -Encoding 'UTF8'
17+
Write-Host $msg
18+
}
19+
20+
$boshWinRMDir = 'C:\Program Files\WindowsPowerShell\Modules\BOSH.WinRM'
21+
Write-Log "Making bosh module directory: $boshWinRMDir"
22+
New-Item -Path $boshWinRMDir -ItemType Directory -Force
23+
224
$winrmUrl = 'https://raw.githubusercontent.com/cloudfoundry/bosh-psmodules/master/modules/BOSH.WinRM/BOSH.WinRM.psm1'
325

4-
$dir = 'C:\Program Files\WindowsPowerShell\Modules\BOSH.WinRM'
5-
New-Item -Path $dir -ItemType Directory -Force
26+
Write-Log "Fetching bosh module $winrmUrl"
27+
Invoke-WebRequest $winrmUrl -OutFile "$boshWinRMDir\BOSH.WinRM.psm1"
28+
29+
if (-not (Get-Command Enable-WinRM -errorAction SilentlyContinue))
30+
{
31+
Write-Log "Enable-WinRM was not loaded. There may be a problem with $winrmUrl"
32+
}
633

7-
Invoke-WebRequest $winrmUrl -OutFile "$dir\BOSH.WinRM.psm1"
34+
Write-Log "Invoking WinRM"
835
Enable-WinRM
936

1037
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope LocalMachine

scripts/gcp/setup-winrm.ps1

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
function Write-Log {
2-
Param (
3-
[Parameter(Mandatory=$True,Position=1)][string]$Message,
4-
[string]$LogFile="C:\provision\log.log"
5-
)
1+
function Write-Log
2+
{
3+
Param (
4+
[Parameter(Mandatory = $True, Position = 1)][string]$Message,
5+
[string]$LogFile = "C:\provision\log.log"
6+
)
67

7-
$LogDir = (split-path $LogFile -parent)
8-
If ((Test-Path $LogDir) -ne $True) {
9-
New-Item -Path $LogDir -ItemType Directory -Force
10-
}
8+
$LogDir = (split-path $LogFile -parent)
9+
If ((Test-Path $LogDir) -ne $True)
10+
{
11+
New-Item -Path $LogDir -ItemType Directory -Force
12+
}
1113

12-
$msg = "{0} {1}" -f (Get-Date -Format o), $Message
13-
Add-Content -Path $LogFile -Value $msg -Encoding 'UTF8'
14-
Write-Host $msg
14+
$msg = "{0} {1}" -f (Get-Date -Format o), $Message
15+
Add-Content -Path $LogFile -Value $msg -Encoding 'UTF8'
16+
Write-Host $msg
1517
}
1618

19+
$boshWinRMDir = 'C:\Program Files\WindowsPowerShell\Modules\BOSH.WinRM'
20+
Write-Log "Making bosh module directory: $boshWinRMDir"
21+
New-Item -Path $boshWinRMDir -ItemType Directory -Force
22+
1723
$winrmUrl = 'https://raw.githubusercontent.com/cloudfoundry/bosh-psmodules/master/modules/BOSH.WinRM/BOSH.WinRM.psm1'
18-
Write-Log "Making bosh module directory"
19-
$dir = 'C:\Program Files\WindowsPowerShell\Modules\BOSH.WinRM'
20-
New-Item -Path $dir -ItemType Directory -Force
2124

22-
Write-Log "Fetching bosh module"
23-
Invoke-WebRequest $winrmUrl -OutFile "$dir\BOSH.WinRM.psm1"
25+
Write-Log "Fetching bosh module $winrmUrl"
26+
Invoke-WebRequest $winrmUrl -OutFile "$boshWinRMDir\BOSH.WinRM.psm1"
2427

25-
if (-not(Get-Command Enable-WinRM -errorAction SilentlyContinue))
28+
if (-not (Get-Command Enable-WinRM -errorAction SilentlyContinue))
2629
{
27-
Write-Log "Enable-WinRM was not loaded. There may be a problem with $winrmUrl"
30+
Write-Log "Enable-WinRM was not loaded. There may be a problem with $winrmUrl"
2831
}
2932

30-
Write-Log "Invoking winrm"
33+
Write-Log "Invoking WinRM"
3134
Enable-WinRM

0 commit comments

Comments
 (0)