forked from usui-tk/amazon-ec2-userdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2nd-Decision_WindowsServer-Version.ps1
156 lines (120 loc) · 6.75 KB
/
2nd-Decision_WindowsServer-Version.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
########################################################################################################################
#.SYNOPSIS
#
# Amazon EC2 Decision Script - 2nd Decision
#
#.DESCRIPTION
#
# Uses option settings to Windows Server Configuration
#
#.NOTES
#
# Target Windows Server OS Version and Processor Architecture (64bit Only)
#
# - 6.1 : Windows Server 2008 R2 (Microsoft Windows Server 2008 R2 SP1 [Datacenter Edition])
# [Windows_Server-2008-R2_SP1-Japanese-64Bit-Base-YYYY.MM.DD]
# [Windows_Server-2008-R2_SP1-English-64Bit-Base-YYYY.MM.DD]
#
# - 6.2 : Windows Server 2012 (Microsoft Windows Server 2012 [Standard Edition])
# [Windows_Server-2012-RTM-Japanese-64Bit-Base-YYYY.MM.DD]
# [Windows_Server-2012-RTM-English-64Bit-Base-YYYY.MM.DD]
#
# - 6.3 : Windows Server 2012 R2 (Microsoft Windows Server 2012 R2 [Standard Edition])
# [Windows_Server-2012-R2_RTM-Japanese-64Bit-Base-YYYY.MM.DD]
# [Windows_Server-2012-R2_RTM-English-64Bit-Base-YYYY.MM.DD]
#
# - 10.0 : Windows Server 2016 (Microsoft Windows Server 2016 [Datacenter Edition])
# [Windows_Server-2016-Japanese-Full-Base-YYYY.MM.DD]
# [Windows_Server-2016-English-Full-Base-YYYY.MM.DD]
#
########################################################################################################################
#-----------------------------------------------------------------------------------------------------------------------
# User Define Parameter
#-----------------------------------------------------------------------------------------------------------------------
# Set Script Parameter for Directory Name (User Defined)
Set-Variable -Name TEMP_DIR -Scope Script "$Env:SystemRoot\Temp"
# Set Script Parameter for Log File Name (User Defined)
Set-Variable -Name USERDATA_LOG -Scope Script "$TEMP_DIR\userdata.log"
Set-Variable -Name TRANSCRIPT_LOG -Scope Script "$TEMP_DIR\userdata-transcript-2nd.log"
# Set Script Parameter for 3rd-Bootstrap Script (User Defined)
Set-Variable -Name BOOTSTRAP_URL -Scope Script -Value "https://raw.githubusercontent.com/usui-tk/amazon-ec2-userdata/master/3rd-Bootstrap_WindowsServer.ps1"
Set-Variable -Name BOOTSTRAP_SCRIPT -Scope Script -Value "3rd-Bootstrap_WindowsServer.ps1"
########################################################################################################################
#
# Windows Bootstrap Common function
#
########################################################################################################################
function Format-Message {
param([string]$message)
$timestamp = Get-Date -Format "yyyy/MM/dd HH:mm:ss.fffffff zzz"
"$timestamp - $message"
} # end function Format-Message
function Write-Log {
param([string]$message, $log = $USERDATA_LOG)
Format-Message $message | Out-File $log -Append -Force
} # end function Write-Log
function Write-LogSeparator {
param([string]$message)
Write-Log "#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
Write-Log ("# Script Executetion Step : " + $message)
Write-Log "#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
} # end function Write-LogSeparator
########################################################################################################################
#
# Start of script
#
########################################################################################################################
#-----------------------------------------------------------------------------------------------------------------------
# Preparation for script execution
#-----------------------------------------------------------------------------------------------------------------------
Start-Transcript -Path "$TRANSCRIPT_LOG" -Append -Force
Set-Variable -Name ScriptFullPath -Scope Script -Value ($MyInvocation.InvocationName)
Write-Log "# Script Execution 2nd-Decision Script [START] : $ScriptFullPath"
Set-Location -Path $TEMP_DIR
Get-ExecutionPolicy -List
Set-StrictMode -Version Latest
#-----------------------------------------------------------------------------------------------------------------------
# Windows Server OS Decision
#-----------------------------------------------------------------------------------------------------------------------
# Log Separator
Write-LogSeparator "Windows Server OS Decision"
#Get OS Infomation & Language
$Local:OSLanguage = ([CultureInfo]::CurrentCulture).IetfLanguageTag
$Local:OSversion = (Get-CimInstance Win32_OperatingSystem | Select-Object Version).Version
Write-Log ("# [Windows Infomation] OS Version : " + ($OSversion) + " - OS Language : " + ($OSLanguage))
# Bootstrap Script Executite
if ($OSversion -match "^6.1.*") {
# Log Separator
Write-LogSeparator "# [Bootstrap Script] : Microsoft Windows Server 2008 R2"
Write-Log ("# [Bootstrap Script] : " + ($BOOTSTRAP_URL))
Invoke-WebRequest -Uri $BOOTSTRAP_URL -OutFile $BOOTSTRAP_SCRIPT
Write-Log "# Script Execution 2nd-Decision Script [COMPLETE] : $ScriptFullPath"
powershell.exe -ExecutionPolicy Bypass .\$BOOTSTRAP_SCRIPT -SkipNetworkProfileCheck
}
elseif ($OSversion -match "^6.2.*") {
# Log Separator
Write-LogSeparator "# [Bootstrap Script] : Microsoft Windows Server 2012"
Write-Log ("# [Bootstrap Script] : " + ($BOOTSTRAP_URL))
Invoke-WebRequest -Uri $BOOTSTRAP_URL -OutFile $BOOTSTRAP_SCRIPT
Write-Log "# Script Execution 2nd-Decision Script [COMPLETE] : $ScriptFullPath"
powershell.exe -ExecutionPolicy Bypass .\$BOOTSTRAP_SCRIPT -SkipNetworkProfileCheck
}
elseif ($OSversion -match "^6.3.*") {
# Log Separator
Write-LogSeparator "# [Bootstrap Script] : Microsoft Windows Server 2012 R2"
Write-Log ("# [Bootstrap Script] : " + ($BOOTSTRAP_URL))
Invoke-WebRequest -Uri $BOOTSTRAP_URL -OutFile $BOOTSTRAP_SCRIPT
Write-Log "# Script Execution 2nd-Decision Script [COMPLETE] : $ScriptFullPath"
powershell.exe -ExecutionPolicy Bypass .\$BOOTSTRAP_SCRIPT -SkipNetworkProfileCheck
}
elseif ($OSversion -match "^10.0.*") {
# Log Separator
Write-LogSeparator "# [Bootstrap Script] : Microsoft Windows Server 2016"
Write-Log ("# [Bootstrap Script] : " + ($BOOTSTRAP_URL))
Invoke-WebRequest -Uri $BOOTSTRAP_URL -OutFile $BOOTSTRAP_SCRIPT
Write-Log "# Script Execution 2nd-Decision Script [COMPLETE] : $ScriptFullPath"
powershell.exe -ExecutionPolicy Bypass .\$BOOTSTRAP_SCRIPT -SkipNetworkProfileCheck
}
else {
Write-Log ("# [Warning] No Target - Windows NT Version Information : " + $OSversion)
}