forked from DeanCefola/Azure-WVD
/
New-WVDSessionHost.ps1
430 lines (397 loc) · 14.1 KB
/
New-WVDSessionHost.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<#Author : Dean Cefola
# Creation Date: 09-15-2019
# Usage : Windows Virtual Desktop Scripted Install
#********************************************************************************
# Date Version Changes
#------------------------------------------------------------------------
# 09/15/2019 1.0 Intial Version
# 09/16/2019 2.0 Add FSLogix installer
# 09/16/2019 2.1 Add FSLogix Reg Keys
# 09/16/2019 2.2 Add Input Parameters
# 09/16/2019 2.3 Add TLS 1.2 settings
# 09/17/2019 3.0 Chang download locations to dynamic
# 09/17/2019 3.1 Add code to disable IESEC for admins
# 09/20/2019 3.2 Add code to discover OS (Server / Client)
# 09/20/2019 4.0 Add code for servers to add RDS Host role
# 10/01/2019 4.2 Add all FSLogix Profile Container Reg entries for easier management
# 10/07/2019 4.3 Add FSLogix Office Container Reg entries for easier management
# 10/16/2019 5.0 Add Windows 7 Support
# 12/05/2019 6.0 Add Azure NetApp Files Support (Author: Kirk Ryan)
#*********************************************************************************
#
#>
######################
# WVD Variables #
######################
$Localpath = "c:\temp\wvd\"
$WVDBootURI = 'https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RWrxrH'
$WVDAgentURI = 'https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RWrmXv'
$FSLogixURI = 'https://go.microsoft.com/fwlink/?linkid=2084562'
$FSInstaller = 'FSLogixAppsSetup.zip'
$ANFEnabled = $true # Refer to https://kirkryan.co.uk/2019/12/04/windows-virtual-desktop-(and-citrix)-with-fslogix for full deployment instructions
$ANFSMBPath = "" # Insert your Azure NetApp Files SMB volume path here
$WVDAgentInstaller = 'WVD-Agent.msi'
$WVDBootInstaller = 'WVD-Bootloader.msi'
$Win7x64_UpdateURI = 'https://download.microsoft.com/download/A/F/5/AF5C565C-9771-4BFB-973B-4094C1F58646/Windows6.1-KB2592687-x64.msu'
$Win7x64_WMI5URI = 'https://download.microsoft.com/download/6/F/5/6F5FF66C-6775-42B0-86C4-47D41F2DA187/Win7AndW2K8R2-KB3191566-x64.zip'
$Win7x64_UpdateInstaller = 'Win7-KB2592687-x64.msu'
$Win7x64_WMI5Installer = 'Win7-KB3191566-WMI5-x64.zip'
$Win7x64_WVDAgentURI = 'https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RE3JZCm'
$Win7x64_WVDBootMgrURI = 'https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RE3K2e3'
#############################
WVD Script Parameters #
#############################
if (($ANFEnabled) -eq $false) {
Param (
[Parameter(Mandatory = $true)]
[string]$ProfilePath,
[Parameter(Mandatory = $true)]
[string]$RegistrationToken
)
}
else {
Param (
[Parameter(Mandatory = $true)]
[string]$RegistrationToken
)
}
####################################
# Test/Create Temp Directory #
####################################
if ((Test-Path $Localpath) -eq $false) {
Write-Host `
-ForegroundColor Cyan `
-BackgroundColor Black `
"creating temp directory"
New-Item -Path $Localpath -ItemType Directory
}
else {
Write-Host `
-ForegroundColor Yellow `
-BackgroundColor Black `
"temp directory already exists"
}
#################################
# Download WVD Componants #
#################################
Invoke-WebRequest -Uri $WVDBootURI -OutFile "$Localpath$WVDBootInstaller"
Invoke-WebRequest -Uri $WVDAgentURI -OutFile "$Localpath$WVDAgentInstaller"
Invoke-WebRequest -Uri $FSLogixURI -OutFile "$Localpath$FSInstaller"
##############################
# Prep for WVD Install #
##############################
Expand-Archive `
-LiteralPath "C:\temp\wvd\$FSInstaller" `
-DestinationPath "$Localpath\FSLogix" `
-Force `
-Verbose
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
cd $Localpath
##############################
# OS Specific Settings #
##############################
$OS = (Get-WmiObject win32_operatingsystem).name
If (($OS) -match 'server') {
write-host -ForegroundColor Cyan -BackgroundColor Black "Windows Server OS Detected"
If (((Get-WindowsFeature -Name RDS-RD-Server).installstate) -eq 'Installed') {
"Session Host Role is already installed"
}
Else {
"Installing Session Host Role"
Install-WindowsFeature `
-Name RDS-RD-Server `
-Verbose `
-LogPath "$Localpath\RdsServerRoleInstall.txt"
}
$AdminsKey = "SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UsersKey = "SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
$BaseKey = [Microsoft.Win32.RegistryKey]::OpenBaseKey("LocalMachine", "Default")
$SubKey = $BaseKey.OpenSubkey($AdminsKey, $true)
$SubKey.SetValue("IsInstalled", 0, [Microsoft.Win32.RegistryValueKind]::DWORD)
$SubKey = $BaseKey.OpenSubKey($UsersKey, $true)
$SubKey.SetValue("IsInstalled", 0, [Microsoft.Win32.RegistryValueKind]::DWORD)
}
Else {
write-host -ForegroundColor Cyan -BackgroundColor Black "Windows Client OS Detected"
if (($OS) -match 'Windows 10') {
write-host `
-ForegroundColor Yellow `
-BackgroundColor Black `
"Windows 10 detected...skipping to next step"
}
else {
$OSArch = (Get-WmiObject win32_operatingsystem).OSArchitecture
If (($OSArch) -match '64-bit') {
write-host `
-ForegroundColor Magenta `
-BackgroundColor Black `
"Windows 7 x64 detected"
#################################
# Begin Win7x64 downloads #
#################################
$Win7x64_WinUpdateRequest = [System.Net.WebRequest]::Create($Win7x64_UpdateURI)
$Win7x64_WMI5Request = [System.Net.WebRequest]::Create($Win7x64_WMI5URI)
$Win7x64_WVDAgentRequest = [System.Net.WebRequest]::Create($Win7x64_WVDAgentURI)
$Win7x64_WVDBootRequest = [System.Net.WebRequest]::Create($Win7x64_WVDBootMgrURI)
################################
# Begin Win7x64 Installs #
################################
write-host `
-ForegroundColor Magenta `
-BackgroundColor Black `
"...installing Update KB2592687 for x64"
Expand-Archive `
-LiteralPath "C:\temp\wvd\$Win7x64_WMI5Installer" `
-DestinationPath "$Localpath\Win7Wmi5x64" `
-Force `
-Verbose
$packageName = 'Win7AndW2K8R2-KB3191566-x64.msu'
$packagePath = 'C:\temp\wvd\Win7Wmi5x64'
$wusaExe = "$env:windir\system32\wusa.exe"
$wusaParameters += @("/quiet", "/promptrestart")
$wusaParameterString = $wusaParameters -join " "
& $wusaExe $wusaParameterString
}
}
}
################################
# Install WVD Componants #
################################
$bootloader_deploy_status = Start-Process `
-FilePath "msiexec.exe" `
-ArgumentList "/i $WVDBootInstaller", `
"/quiet", `
"/qn", `
"/norestart", `
"/passive", `
"/l* $Localpath\AgentBootLoaderInstall.txt" `
-Wait `
-Passthru
$sts = $bootloader_deploy_status.ExitCode
Write-Output "Installing RDAgentBootLoader on VM Complete. Exit code=$sts`n"
Wait-Event -Timeout 5
Write-Output "Installing RD Infra Agent on VM $AgentInstaller`n"
$agent_deploy_status = Start-Process `
-FilePath "msiexec.exe" `
-ArgumentList "/i $WVDAgentInstaller", `
"/quiet", `
"/qn", `
"/norestart", `
"/passive", `
"REGISTRATIONTOKEN=$RegistrationToken", "/l* $Localpath\AgentInstall.txt" `
-Wait `
-Passthru
Wait-Event -Timeout 5
#########################
# FSLogix Install #
#########################
$fslogix_deploy_status = Start-Process `
-FilePath "$Localpath\FSLogix\x64\Release\FSLogixAppsSetup.exe" `
-ArgumentList "/install /quiet" `
-Wait `
-Passthru
#######################################
# FSLogix User Profile Settings #
#######################################
Push-Location
Set-Location HKLM:\SOFTWARE\FSLogix
New-Item `
-Path HKLM:\SOFTWARE\FSLogix `
-Name Profiles `
-Value "" `
-Force
if (($ANFEnabled) -eq $false) {
Write-Host `
-ForegroundColor Cyan `
-BackgroundColor Black `
"using CCD location"
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "CCDLocations" `
-PropertyType "MultiString" `
-Value "type=smb,connectionString=$ProfilePath;type=smb,connectionString=\\msdean.file.core.windows.net\fslogix"
}
else {
Write-Host `
-ForegroundColor Yellow `
-BackgroundColor Black `
"setting VHDLocation for Azure NetApp Files"
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "VHDLocations" `
-PropertyType "MultiString" `
-Value $ANFSMBPath
}
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "Enabled" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "DeleteLocalProfileWhenVHDShouldApply" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "FlipFlopProfileDirectoryName" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "PreventLoginWithFailure" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "PreventLoginWithTempProfile" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "RebootOnUserLogoff" `
-PropertyType "DWord" `
-Value 0
New-ItemProperty `
-Path HKLM:\SOFTWARE\FSLogix\Profiles `
-Name "ShutdownOnUserLogoff" `
-PropertyType "DWord" `
-Value 0
Pop-Location
#########################################
# FSLogix Office Profile Settings #
#########################################
Push-Location
Set-Location HKLM:\SOFTWARE\Policies
New-Item `
-Name FSLogix `
-Value "" `
-Force
New-Item `
-Path .\FSLogix `
-Name ODFC `
-Value "" `
-Force
if (($ANFEnabled) -eq $false) {
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "CCDLocations" `
-PropertyType "MultiString" `
-Value "type=smb,connectionString=$ProfilePath;type=smb,connectionString=\\msdean.file.core.windows.net\fslogix"
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "Enabled" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "DeleteLocalProfileWhenVHDShouldApply" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "FlipFlopProfileDirectoryName" `
-PropertyType "DWord" `
-Value 0
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "PreventLoginWithFailure" `
-PropertyType "DWord" `
-Value 0
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "PreventLoginWithTempProfile" `
-PropertyType "DWord" `
-Value 0
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeOneDrive" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeOneNote" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeOneNote_UWP" `
-PropertyType "DWord" `
-Value 0
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeOutlook" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeOutlookPersonalization" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeSharepoint" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeSkype" `
-PropertyType "DWord" `
-Value 1
New-ItemProperty `
-Path .\FSLogix\ODFC `
-Name "IncludeTeams" `
-PropertyType "DWord" `
-Value 1
Pop-Location
}
#############
# END #
#############
Restart-Computer -Force
<######################
# App Creation #
######################
$AppPath = '\\MSAzureAcademy.com\CorpShares\AppAttach'
$Apps = Get-ChildItem -Path $AppPath | Where-Object -Property Name -Match .msix
foreach ($App in $Apps){
$MSISource = "$AppPath\$App"
$Package = $app.Name
$VHDSource = $Package.Replace('.msix','.vhd')
$PackageName = $Package.Replace('.msix','')
$MSIXDestination = "C:\Program Files\WindowsApps\"+$PackageName
Write-Host `
-ForegroundColor Cyan `
-BackgroundColor Black `
$App
}
############################
# Enable Sideloading #
############################
$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
$Name1 = "AllowAllTrustedApps"
$value1 = "1"
$Name2 = "AllowDevelopmentWithoutDevLicense"
$value2 = "0"
New-ItemProperty `
-Path $registryPath `
-Name $name1 `
-Value $value1 `
-PropertyType DWORD `
-Force
New-ItemProperty `
-Path $registryPath `
-Name $name2 `
-Value $value2 `
-PropertyType DWORD `
-Force
####################
# App Attach #
####################
New-RdsRemoteApp `
-TenantName $tenantname `
-HostPoolName $hostpoolname `
-AppGroupName $AppGroupName `
-Name "VLC" `
-FilePath "C:\Program Files\WindowsApps\VLC_1.0.4.0_x64__s11z9dr7vpbt2\VFS\ProgramFilesX86\VideoLAN\VLC\vlc.exe"
#>