-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAIB-OptimizeImage.ps1
161 lines (152 loc) · 5.76 KB
/
AIB-OptimizeImage.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
<#
Script purpose: Optimize AVD Image
Version: 1.0
Date: 18-01-2022
Author: John Eijgensteijn
Change log: First release
#>
#region Variables
$TempPath="c:\Temp\Software"
$LogPath="C:\Programdata\PPC\"
$Logfile="Software_Install.log"
#repo for app installation parameters
$repo="https://dev.azure.com/ProactBenelux/d4523fbb-bde0-48ff-9be6-e3fb84165b1a/_apis/git/repositories/92abb40d-73cf-49ef-9a5c-cbed18018b12/items?path="
$storageaccount="https://ppcavdstorage.blob.core.windows.net/avdbuild?sp=r&st=2022-02-24T08:31:07Z&se=2023-02-24T16:31:07Z&spr=https&sv=2020-08-04&sr=c&sig=8NGsByN%2BkHPpTsFIZvRubQ%2FqfN1c1Hig7pDAyqXmZfo%3D"
#region create folders
#Create folder for Logfile storage
#Create Temp folder for Software download and Extract
try {
If (!(Test-path -Path $TempPath -ErrorAction Ignore)) {New-Item -ItemType Directory $TempPath }
}
catch {
$ErrorMessage = $_.Exception.message
Write-Output "Error creating temp folder $ErrorMessage"
}
If (!(Test-Path -Path $LogPath -ErrorAction Ignore)) {New-Item -ItemType Directory $LogPath }
#Create folder for Languagefile storage
try {
$LanguagePath=$TempPath+"\nl"
If (!(Test-Path -Path $LanguagePath -ErrorAction Ignore)) {New-Item -ItemType Directory $LanguagePath}
}
catch {
$ErrorMessage = $_.Exception.message
Write-Output "Error creating Log folder $ErrorMessage"
}
#endregion create folders
#region Optimize AVD
try {#Enable RDP Shortpath","Description":"This script enables the preview function for RDP Shortpath on the selected session hosts
$WinstationsKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations'
New-ItemProperty -Path $WinstationsKey -Name 'fUseUdpPortRedirector' -ErrorAction:SilentlyContinue -PropertyType:dword -Value 1 -Force -Verbose
New-ItemProperty -Path $WinstationsKey -Name 'UdpPortNumber' -ErrorAction:SilentlyContinue -PropertyType:dword -Value 3390 -Force -Verbose
New-NetFirewallRule -DisplayName 'Remote Desktop - Shortpath (UDP-In)' -Action Allow -Description 'Inbound rule for the Remote Desktop service to allow RDP traffic. [UDP 3390]' -Group '@FirewallAPI.dll,-28752' -Name 'RemoteDesktop-UserMode-In-Shortpath-UDP' -PolicyStore PersistentStore -Profile Domain, Private -Service TermService -Protocol udp -LocalPort 3390 -Program '%SystemRoot%\system32\svchost.exe' -Enabled:True -Verbose
if (Test-Path $WinstationsKey\$fUseUdpPortRedirector -Verbose) {
write-host "fUseUdpPortRedirector regkey has been created"
}
else {
write-host "Error creating RDP Shortpath regkeys"
}
}
catch {
$ErrorMessage = $_.Exception.message
write-host "Error creating RDP Shortpath regkeys $ErrorMessage"
}
#endregion
#region AppxOverride
#Create Appx Override to improve login time for available Appx packages
$appname="Appxoverride"
try {
$Arguments = @(
"IMPORT"
"$TempPath\AVDBuild\AppxOverride.reg"
)
Start-Process -filepath "reg.exe" -Wait -ErrorAction Stop -ArgumentList $Arguments -Verbose
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\OverrideConfig" -Verbose) {
write-host "$appname has been installed"
}
else {
write-host "Error installing $appname"
}
}
catch {
$ErrorMessage = $_.Exception.message
write-host "Error installing $appname Host $ErrorMessage"
}
#endregion
#region Citrix Optimizer
$appname="Citrix Optimizer"
Expand-Archive "$TempPath\avdbuild\CitrixOptimizer.zip" -DestinationPath "$TempPath\avdbuild\CitrixOptimizer"
$XML="$TempPath\avdbuild\CitrixOptimizer\W10-21H2.XML"
$RollbackXML="$LogPath\Rollback-W10-21H2.xml"
try {
invoke-expression "$TempPath\avdbuild\CitrixOptimizer\CtxOptimizerEngine.ps1 -Source $XML -Mode Execute -OutputXml $RollbackXML" -Verbose
if (Test-Path $RollbackXML -Verbose) {
write-host "$appname has been installed"
}
else {
write-host "Error installing $appname"
}
}
catch {
$ErrorMessage = $_.Exception.message
write-host "Error installing $appname Host $ErrorMessage"
}
#endregion
#region remove ActiveSetup
#clear windows Active Setup to improve login times of the WVD session
try {
$RegPath='HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\*'
Remove-Item -Path $RegPath -Recurse -Force
$RegPath = $RegPath.Substring(0,$RegPath.Length-1)
$items=Get-ChildItem -Path $RegPath
$items.count
if ($items.count -eq 0) {
write-host "Active Setup Cleared"
}
else {
write-host "Error clearing Active Setup"
}
}
catch {
$ErrorMessage = $_.Exception.message
write-host "Error clearing Active Setup: $ErrorMessage"
}
try {
$RegPath64='HKLM:\SOFTWARE\WOW6432Node\Microsoft\Active Setup\Installed Components\*'
Remove-Item -Path $RegPath64 -Recurse -Force
$RegPath64 = $RegPath64.Substring(0,$RegPath64.Length-1)
$items=Get-ChildItem -Path $RegPath64
$items.count
if ($items.count -eq 0) {
write-host "Active Setup WOW6432Node Cleared"
}
else {
write-host "Error clearing Active Setup WOW6432Node"
}
}
catch {
$ErrorMessage = $_.Exception.message
write-host "Error clearing Active Setup WOW6432Node: $ErrorMessage"
}
#endregion
#region Enable-PSRemoting
try {
Enable-PSRemoting -Force -SkipNetworkProfileCheck -Verbose
write-host "Enabled PSRemoting" }
catch {
$ErrorMessage = $_.Exception.message
write-host "Error enabling PSRemoting $ErrorMessage"
}
#endregion
#region Cleanup
try {
Get-ChildItem $TempPath -Recurse | Remove-Item -Force -Recurse -Verbose
write-host "Cleanup of Temp storage"
}
catch {
$ErrorMessage = $_.Exception.message
write-host "Error Cleanup of temp $appname $ErrorMessage"
}
#endregion
#region FSLogix Exclusion
Get-LocalGroup 'administrators' | Add-LocalGroupMember -Name 'FSLogix Profile Exclude List'
#endregion