forked from HCK-CI/HLK-Setup-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudio.ps1
146 lines (115 loc) · 4.78 KB
/
studio.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
$ErrorActionPreference = "Stop"
. "$PSScriptRoot\auxiliary.ps1"
. "$PSScriptRoot\common.ps1"
. "$PSScriptRoot\extra_software.ps1"
function Enable-NtpServer {
Write-Output "Enabling NTP Server on Studio VM..."
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer' -Name 'Enabled' -Value 1
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Config' -Name 'AnnounceFlags' -Value 5
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters' -Name 'Type' -Value 'NTP'
}
function Stage-One {
Set-NewStage -Stage "Two"
Allow-InsecureGuestAuth
Disable-ServerManagerStartupPopup
Disable-WindowsFirewall
Set-UnidentifiedNetworksToPrivateLocation
Disable-WindowsUpdate
Disable-Screensaver
Disable-PowerSavingOptions
Rename-Computer -NewName "$STUDIOCOMPUTERNAME"
Get-NetAdapter | ForEach-Object {
$adapterName = $_.Name
$adapterMac = $_.MacAddress
$lastMacSegment = $adapterMac.Substring($adapterMac.Length - 2)
switch ($lastMacSegment) {
"CC" {
Write-Output "Setting static IP address to control Network adapter..."
New-NetIPAddress -InterfaceAlias $adapterName -IPAddress "$STUDIOIP" -PrefixLength 24
Write-Output "Renaming Control Network adapter..."
Rename-NetAdapter -Name "$adapterName" -NewName "Control"
Break
}
"DD" {
Write-Output "Renaming External Network adapter..."
Rename-NetAdapter -Name "$adapterName" -NewName "External"
Break
}
Default {
Write-Output "Adapter $adapterName with MAC $adapterMac. Skipped..."
Break
}
}
}
Write-Output "Adding clients Powershell remoting port proxy..."
Execute-Command -Path "netsh.exe" -Arguments "interface portproxy add v4tov4 listenport=4002 connectaddress=${CONTROLNET}.2 connectport=5985"
Execute-Command -Path "netsh.exe" -Arguments "interface portproxy add v4tov4 listenport=4003 connectaddress=${CONTROLNET}.3 connectport=5985"
Enable-PowerShellRemoting
Enable-NtpServer
Safe-Restart
}
function Stage-Two {
Set-NewStage -Stage "Three"
Install-StudioExtraSoftwareBeforeKit
Safe-Restart
}
function Stage-Three {
Set-NewStage -Stage "Four"
Write-Output "Installing $KITTYPE, this might take a while..."
$kitPath = $null
$kitArgs = "/q"
if ($KITTYPE -eq "HLK") {
$disks = Get-WmiObject -Class Win32_LogicalDisk
foreach ($disk in ($disks | Where-Object { $_.DriveType -eq 5 })) {
$kitPathInDisk = Join-Path -Path $disk.DeviceID -ChildPath "HLKSetup.exe"
if (Test-Path -Path $kitPathInDisk) {
$kitPath = $kitPathInDisk
break
}
}
if ($kitPath -eq $null) {
if (Test-Path -Path "$PSScriptRoot\Kits\HLK${HLKKITVER}\HLKSetup.exe") {
$kitPath = "$PSScriptRoot\Kits\HLK${HLKKITVER}\HLKSetup.exe"
} else {
$kitPath = "$PSScriptRoot\Kits\HLK${HLKKITVER}Setup.exe"
}
}
} else {
if (Test-Path -Path "%~dp0Kits\HCK\HCKSetup.exe") {
$kitPath = "$PSScriptRoot\Kits\HCK\Setup.exe"
} else {
$kitPath = "$PSScriptRoot\Kits\HCKSetup.exe"
}
}
Execute-Command -Path "$kitPath" -Arguments "$kitArgs"
Write-Output "$KITTYPE Studio setup has finished..."
if ($REMOVEGUI -eq $TRUE) {
Remove-WindowsGUI
}
Safe-Restart
}
function Stage-Four {
Set-NewStage -Stage "Five"
Write-Output "Downloading and updating Filters..."
if (!(Test-Path -Path "$env:DTMBIN")) {
Write-Error "Folder $env:DTMBIN does not exist! Please verify that you have the controller installed."
}
$filtersFile = "$env:TEMP\FilterUpdates.cab"
Execute-Command -Path "bitsadmin.exe" -Arguments "/transfer `"Downloading Filters`" `"$FILTERS`" `"$filtersFile`""
Execute-Command -Path "expand.exe" -Arguments "-i `"$filtersFile`" -f:UpdateFilters.sql `"$env:DTMBIN\`""
Remove-Item -Path "$filtersFile"
Push-Location -Path "$env:DTMBIN\"
Execute-Command -Path "$env:DTMBIN\updatefilters.exe" -Arguments "/s"
Remove-Item -Path "UpdateFilters.sql"
Pop-Location
Get-Service -Name "winrm"
Write-Output "$env:DTMBIN"
Safe-Restart
}
function Stage-Five {
Remove-Stage
Remove-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "install"
Install-StudioExtraSoftwareAfterKit
Safe-Shutdown
}
Start-Stage