forked from ecalder6/azure-gaming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.psm1
294 lines (238 loc) · 13.4 KB
/
utils.psm1
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
[Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$webClient = new-object System.Net.WebClient
$webClient.Headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0';
function Disable-InternetExplorerESC {
# From https://stackoverflow.com/questions/9368305/disable-ie-security-on-windows-server-via-powershell
$AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -Force
Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -Force
Stop-Process -Name Explorer -Force
Write-Output "IE Enhanced Security Configuration (ESC) has been disabled." -ForegroundColor Green
}
function Update-Windows {
$url = "https://gallery.technet.microsoft.com/scriptcenter/Execute-Windows-Update-fc6acb16/file/144365/1/PS_WinUpdate.zip"
$compressed_file = "PS_WinUpdate.zip"
$update_script = "PS_WinUpdate.ps1"
Write-Output "Downloading Windows Update Powershell Script from $url"
$webClient.DownloadFile($url, "$PSScriptRoot\$compressed_file")
Unblock-File -Path "$PSScriptRoot\$compressed_file"
Write-Output "Extracting Windows Update Powershell Script"
Expand-Archive "$PSScriptRoot\$compressed_file" -DestinationPath "$PSScriptRoot\" -Force
Write-Output "Running Windows Update"
Invoke-Expression $PSScriptRoot\$update_script
}
function Update-Firewall {
Write-Output "Enable ICMP Ping in Firewall."
Set-NetFirewallRule -DisplayName "File and Printer Sharing (Echo Request - ICMPv4-In)" -Enabled True
}
function Disable-Defender {
Write-Output "Disable Windows Defender real-time protection."
Set-MpPreference -DisableRealtimeMonitoring $true
}
function Disable-ScheduledTasks {
Write-Output "Disable unnecessary scheduled tasks"
Disable-ScheduledTask -TaskName 'ScheduledDefrag' -TaskPath '\Microsoft\Windows\Defrag'
Disable-ScheduledTask -TaskName 'ProactiveScan' -TaskPath '\Microsoft\Windows\Chkdsk'
Disable-ScheduledTask -TaskName 'Scheduled' -TaskPath '\Microsoft\Windows\Diagnosis'
Disable-ScheduledTask -TaskName 'SilentCleanup' -TaskPath '\Microsoft\Windows\DiskCleanup'
Disable-ScheduledTask -TaskName 'WinSAT' -TaskPath '\Microsoft\Windows\Maintenance'
Disable-ScheduledTask -TaskName 'Windows Defender Cache Maintenance' -TaskPath '\Microsoft\Windows\Windows Defender'
Disable-ScheduledTask -TaskName 'Windows Defender Cleanup' -TaskPath '\Microsoft\Windows\Windows Defender'
Disable-ScheduledTask -TaskName 'Windows Defender Scheduled Scan' -TaskPath '\Microsoft\Windows\Windows Defender'
Disable-ScheduledTask -TaskName 'Windows Defender Verification' -TaskPath '\Microsoft\Windows\Windows Defender'
}
function Edit-VisualEffectsRegistry {
Write-Output "Adjust performance options in registry"
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects" -Name "VisualFXSetting" -Value 2
}
function Install-NvidiaDriver ($manual_install) {
# Modified from source: https://github.com/lord-carlos/nvidia-update
Write-Output "Installing Nvidia Driver"
$url = "https://go.microsoft.com/fwlink/?linkid=836843"
$driver_file = "nvidia-driver.exe"
Write-Output "Downloading Nvidia M60 driver from URL $url"
$webClient.DownloadFile($url, "$PSScriptRoot\$driver_file")
Write-Output "Installing Nvidia M60 driver from file $PSScriptRoot\$driver_file"
Start-Process -FilePath "$PSScriptRoot\$driver_file" -ArgumentList "-s", "-noreboot" -Wait
}
function Disable-Devices {
$url = "https://gallery.technet.microsoft.com/PowerShell-Device-60d73bb0/file/147248/2/DeviceManagement.zip"
$compressed_file = "DeviceManagement.zip"
$extract_folder = "DeviceManagement"
Write-Output "Downloading Device Management Powershell Script from $url"
$webClient.DownloadFile($url, "$PSScriptRoot\$compressed_file")
Unblock-File -Path "$PSScriptRoot\$compressed_file"
Write-Output "Extracting Device Management Powershell Script"
Expand-Archive "$PSScriptRoot\$compressed_file" -DestinationPath "$PSScriptRoot\$extract_folder" -Force
Write-Output "Disabling Hyper-V Video"
Import-Module "$PSScriptRoot\$extract_folder\DeviceManagement.psd1"
Get-Device | Where-Object -Property Name -Like "Microsoft Hyper-V Video" | Disable-Device -Confirm:$false
}
function Disable-TCC {
$nvsmi = "C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe"
$gpu = & $nvsmi --format=csv,noheader --query-gpu=pci.bus_id
& $nvsmi -g $gpu -fdm 0
}
function Enable-Audio {
Write-Output "Enabling Audio Service"
Set-Service -Name "Audiosrv" -StartupType Automatic
Start-Service Audiosrv
}
function Install-VirtualAudio {
$compressed_file = "VBCABLE_Driver_Pack43.zip"
$driver_folder = "VBCABLE_Driver_Pack43"
$driver_inf = "vbMmeCable64_win7.inf"
$hardward_id = "VBAudioVACWDM"
Write-Output "Downloading Virtual Audio Driver"
$webClient.DownloadFile("http://vbaudio.jcedeveloppement.com/Download_CABLE/VBCABLE_Driver_Pack43.zip", "$PSScriptRoot\$compressed_file")
Unblock-File -Path "$PSScriptRoot\$compressed_file"
Write-Output "Extracting Virtual Audio Driver"
Expand-Archive "$PSScriptRoot\$compressed_file" -DestinationPath "$PSScriptRoot\$driver_folder" -Force
$wdk_installer = "wdksetup.exe"
$devcon = "C:\Program Files (x86)\Windows Kits\10\Tools\x64\devcon.exe"
Write-Output "Downloading Windows Development Kit installer"
$webClient.DownloadFile("http://go.microsoft.com/fwlink/p/?LinkId=526733", "$PSScriptRoot\$wdk_installer")
Write-Output "Downloading and installing Windows Development Kit"
Start-Process -FilePath "$PSScriptRoot\$wdk_installer" -ArgumentList "/S" -Wait
$cert = "vb_cert.cer"
$url = "https://github.com/Saboti/azure-gaming/raw/master/$cert"
Write-Output "Downloading vb certificate from $url"
$webClient.DownloadFile($url, "$PSScriptRoot\$cert")
Write-Output "Importing vb certificate"
Import-Certificate -FilePath "$PSScriptRoot\$cert" -CertStoreLocation "cert:\LocalMachine\TrustedPublisher"
Write-Output "Installing virtual audio driver"
Start-Process -FilePath $devcon -ArgumentList "install", "$PSScriptRoot\$driver_folder\$driver_inf", $hardward_id -Wait
}
function Install-Chocolatey {
Write-Output "Installing Chocolatey"
Invoke-Expression ($webClient.DownloadString('https://chocolatey.org/install.ps1'))
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
chocolatey feature enable -n allowGlobalConfirmation
}
function Disable-IPv6To4 {
Set-Net6to4Configuration -State disabled
Set-NetTeredoConfiguration -Type disabled
Set-NetIsatapConfiguration -State disabled
}
function Install-VPN {
$cert = "zerotier_cert.cer"
$url = "https://github.com/Saboti/azure-gaming/raw/master/$cert"
Write-Output "Downloading zero tier certificate from $url"
$webClient.DownloadFile($url, "$PSScriptRoot\$cert")
Write-Output "Importing zero tier certificate"
Import-Certificate -FilePath "$PSScriptRoot\$cert" -CertStoreLocation "cert:\LocalMachine\TrustedPublisher"
Write-Output "Installing ZeroTier"
choco install zerotier-one --force
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
}
function Join-Network ($network) {
Write-Output "Joining network $network"
zerotier-cli join $network
}
function Install-NSSM {
Write-Output "Installing NSSM for launching services that run apps at startup"
choco install nssm --force
}
function Install-Steam {
$steam_exe = "steam.exe"
Write-Output "Downloading steam into path $PSScriptRoot\$steam_exe"
$webClient.DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/SteamSetup.exe", "$PSScriptRoot\$steam_exe")
Write-Output "Installing steam"
Start-Process -FilePath "$PSScriptRoot\$steam_exe" -ArgumentList "/S" -Wait
Write-Output "Cleaning up steam installation file"
Remove-Item -Path $PSScriptRoot\$steam_exe -Confirm:$false
}
function Download-gameclients {
$battlenet_exe = "Battle.net-Setup.exe"
Write-Output "Downloading battle.net into path $PSScriptRoot\$battlenet_exe"
$webClient.DownloadFile("https://www.battle.net/download/getInstallerForGame?os=win&locale=enUS&version=LIVE&gameProgram=BATTLENET_APP&id=290573456.1505264452", "$PSScriptRoot\$battlenet_exe")
$swtor_exe = "SWTOR_setup.exe"
Write-Output "Downloading swtor into path $PSScriptRoot\$swtor_exe"
$webClient.DownloadFile("https://swtor-a.akamaihd.net/installer/SWTOR_setup.exe", "$PSScriptRoot\$swtor_exe")
$compressed_file = "bnetlauncher_v122.zip"
$extract_folder = "bnetlauncher"
Write-Output "Downloading bnetlauncher into path $PSScriptRoot\$compressed_file"
$webClient.DownloadFile("https://madalien.com/pub/bnetlauncher/bnetlauncher_v122.zip", "$PSScriptRoot\$compressed_file")
Write-Output "Extracting bnetlauncher"
Expand-Archive "$PSScriptRoot\$compressed_file" -DestinationPath "$PSScriptRoot\$extract_folder" -Force
Write-Output "Cleaning up bnetlauncher compressed file"
Remove-Item -Path $PSScriptRoot\$compressed_file -Confirm:$false
$compressed_file2 = "OriginSteamOverlayLauncher-v1.07d.zip"
$extract_folder2 = "originsteamoverlaylauncher"
Write-Output "Downloading originsteamoverlaylauncher into path $PSScriptRoot\$compressed_file2"
$webClient.DownloadFile("https://github.com/WombatFromHell/OriginSteamOverlayLauncher/releases/download/v1.07d/OriginSteamOverlayLauncher-v1.07d.zip", "$PSScriptRoot\$compressed_file2")
Write-Output "Extracting originsteamoverlaylauncher"
Expand-Archive "$PSScriptRoot\$compressed_file2" -DestinationPath "$PSScriptRoot\$extract_folder2" -Force
Write-Output "Cleaning up originsteamoverlaylauncher compressed file"
Remove-Item -Path $PSScriptRoot\$compressed_file2 -Confirm:$false
}
function Install-Rainway {
choco install dotnet4.7.1 --force
choco install msvisualcplusplus2013-redist --force
choco install vcredist140 --force
$rainwayRelease = Invoke-WebRequest 'https://releases.rainway.io/Installer_current.json' | ConvertFrom-Json
if (!$rainwayRelease) {
Write-Output "Failed to fetch remote Rainway config" -ForegroundColor Red
return
}
$version = $rainwayRelease.Version
$url = "https://releases.rainway.io/Installer_$version.exe"
$downloadedFile = "$PSScriptRoot\RainwayInstaller.exe"
$webClient.DownloadFile($url, $downloadedFile)
Unblock-File -Path $downloadedFile
Write-Output "Installing Rainway ($version) from file $downloadedFile"
Start-Process -FilePath $downloadedFile -ArgumentList "/qn" -Wait
Write-Output "Cleaning up Rainway installation file"
Remove-Item -Path $downloadedFile -Confirm:$false
}
function Set-ScheduleWorkflow ($admin_username, $admin_password, $manual_install) {
$script_name = "setup2.ps1"
$url = "https://raw.githubusercontent.com/Saboti/azure-gaming/master/$script_name"
Write-Output "Downloading second stage setup script from $url"
$webClient.DownloadFile($url, "C:\$script_name")
$powershell = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$service_name = "SetupSecondStage"
Write-Output "Creating a service $service_name to finish setting up"
$cmd = "-ExecutionPolicy Unrestricted -NoProfile -File C:\$script_name -admin_username `"$admin_username`" -admin_password `"$admin_password`""
if ($manual_install) {
$cmd = -join ($cmd, " -manual_install")
}
nssm install $service_name $powershell $cmd
nssm set $service_name Start SERVICE_AUTO_START
nssm set $service_name AppExit 0 Exit
}
function Disable-ScheduleWorkflow {
$service_name = "SetupSecondStage"
nssm remove $service_name confirm
}
function Add-DisconnectShortcut {
# From https://stackoverflow.com/questions/9701840/how-to-create-a-shortcut-using-powershell
Write-Output "Create disconnect shortcut under C:\disconnect.lnk"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("C:\disconnect.lnk")
$Shortcut.TargetPath = "C:\Windows\System32\tscon.exe"
$Shortcut.Arguments = "%sessionname% /dest:console"
$Shortcut.Save()
}
function Add-AutoLogin ($admin_username, $admin_password) {
Write-Output "Make the password and account of admin user never expire."
Set-LocalUser -Name $admin_username -PasswordNeverExpires $true -AccountNeverExpires
Write-Output "Make the admin login at startup."
$registry = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty $registry "AutoAdminLogon" -Value "1" -type String
Set-ItemProperty $registry "DefaultDomainName" -Value "$env:computername" -type String
Set-ItemProperty $registry "DefaultUsername" -Value $admin_username -type String
Set-ItemProperty $registry "DefaultPassword" -Value $admin_password -type String
}
function Install-epicgameslauncher {
choco install epicgameslauncher -y
}
function Install-leagueoflegends {
choco install leagueoflegends -y
}
function Enable-H264 {
Write-Output "Enable H.264 Graphics mode for Remote Desktop."
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows NT\Terminal Services -Name AVCHardwareEncodePreferred -Value 2
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows NT\Terminal Services -Name AVC444ModePreferred -Value 1
}