-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSAT_Install.ps1
218 lines (194 loc) · 9.52 KB
/
RSAT_Install.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
#Install RSAT for Windows 10 1809 and 1903 and 1909 automated
#https://gallery.technet.microsoft.com/Install-RSAT-for-Windows-75f5f92f
#Get-WindowsCapability -Name RSAT* -Online | Select-Object -Property Name, State
<#
.SYNOPSIS
Install RSAT features for Windows 10 1809 or 1903 or 1909.
.DESCRIPTION
Install RSAT features for Windows 10 1809 or 1903 or 1909. All features are installed online from Microsoft Update thus the script requires Internet access
.PARAM All
Installs all the features within RSAT. This takes several minutes, depending on your Internet connection
.PARAM Basic
Installs ADDS, DHCP, DNS, GPO, ServerManager
.PARAM ServerManager
Installs ServerManager
.PARAM Uninstall
Uninstalls all the RSAT features
.NOTES
Filename: Install-RSATv1809v1903v1909.ps1
Version: 1.2
Author: Martin Bengtsson
Blog: www.imab.dk
Twitter: @mwbengtsson
Version history:
1.0 - Script created
1.2 - Added test for pending reboots. If reboot is pending, RSAT features might not install successfully
Added test for configuration of local WSUS by Group Policy.
- If local WSUS is configured by Group Policy, history shows that additional settings might be needed for some environments
1.3 - Now using Get-CmiInstance instead of Get-WmiObject for determining OS buildnumber
#>
[CmdletBinding()]
param(
[parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[switch]$All,
[parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[switch]$Basic,
[parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[switch]$ServerManager,
[parameter(Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[switch]$Uninstall
)
# Check for administrative rights
if (-NOT([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning -Message "The script requires elevation"
break
}
# Create Pending Reboot function for registry
function Test-PendingRebootRegistry {
$CBSRebootKey = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -ErrorAction Ignore
$WURebootKey = Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction Ignore
if (($CBSRebootKey -ne $null) -OR ($WURebootKey -ne $null)) {
$true
}
else {
$false
}
}
# Windows 10 1809 build
$1809Build = "17763"
# Windows 10 1903 build
$1903Build = "18362"
# Windows 10 1909 build
$1909Build = "18363"
# Get running Windows build
$WindowsBuild = (Get-CimInstance -Class Win32_OperatingSystem).BuildNumber
# Get information about local WSUS server
$WUServer = (Get-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Name WUServer -ErrorAction Ignore).WUServer
#$DualScan = (Get-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Name DisableDualScan -ErrorAction Ignore).DisableDualScan
$TestPendingRebootRegistry = Test-PendingRebootRegistry
if (($WindowsBuild -eq $1809Build) -OR ($WindowsBuild -eq $1903Build) -OR ($WindowsBuild -eq $1909Build)) {
Write-Verbose -Verbose "Running correct Windows 10 build number for installing RSAT with Features on Demand. Build number is: $WindowsBuild"
Write-Verbose -Verbose "***********************************************************"
if ($WUServer -ne $null) {
Write-Verbose -Verbose "A local WSUS server was found configured by group policy: $WUServer"
Write-Verbose -Verbose "You might need to configure additional setting by GPO if things are not working"
Write-Verbose -Verbose "The GPO of interest is following: Specify settings for optional component installation and component repair"
Write-Verbose -Verbose "Check ON: Download repair content and optional features directly from Windows Update..."
Write-Verbose -Verbose "***********************************************************"
}
if ($TestPendingRebootRegistry -eq "True") {
Write-Verbose -Verbose "Reboots are pending. The script will continue, but RSAT might not install successfully"
Write-Verbose -Verbose "***********************************************************"
}
if ($PSBoundParameters["All"]) {
Write-Verbose -Verbose "Script is running with -All parameter. Installing all available RSAT features"
$Install = Get-WindowsCapability -Online | Where-Object {$_.Name -like "Rsat*" -AND $_.State -eq "NotPresent"}
if ($Install -ne $null) {
foreach ($Item in $Install) {
$RsatItem = $Item.Name
Write-Verbose -Verbose "Adding $RsatItem to Windows"
try {
Add-WindowsCapability -Online -Name $RsatItem
}
catch [System.Exception]
{
Write-Verbose -Verbose "Failed to add $RsatItem to Windows"
Write-Warning -Message $_.Exception.Message
}
}
}
else {
Write-Verbose -Verbose "All RSAT features seems to be installed already"
}
}
if ($PSBoundParameters["Basic"]) {
Write-Verbose -Verbose "Script is running with -Basic parameter. Installing basic RSAT features"
# Querying for what I see as the basic features of RSAT. Modify this if you think something is missing. :-)
$Install = Get-WindowsCapability -Online | Where-Object {$_.Name -like "Rsat.ActiveDirectory*" -OR $_.Name -like "Rsat.DHCP.Tools*" -OR $_.Name -like "Rsat.Dns.Tools*" -OR $_.Name -like "Rsat.GroupPolicy*" -OR $_.Name -like "Rsat.ServerManager*" -AND $_.State -eq "NotPresent" }
if ($Install -ne $null) {
foreach ($Item in $Install) {
$RsatItem = $Item.Name
Write-Verbose -Verbose "Adding $RsatItem to Windows"
try {
Add-WindowsCapability -Online -Name $RsatItem
}
catch [System.Exception]
{
Write-Verbose -Verbose "Failed to add $RsatItem to Windows"
Write-Warning -Message $_.Exception.Message
}
}
}
else {
Write-Verbose -Verbose "The basic features of RSAT seems to be installed already"
}
}
if ($PSBoundParameters["ServerManager"]) {
Write-Verbose -Verbose "Script is running with -ServerManager parameter. Installing Server Manager RSAT feature"
$Install = Get-WindowsCapability -Online | Where-Object {$_.Name -like "Rsat.ServerManager*" -AND $_.State -eq "NotPresent"}
if ($Install -ne $null) {
$RsatItem = $Install.Name
Write-Verbose -Verbose "Adding $RsatItem to Windows"
try {
Add-WindowsCapability -Online -Name $RsatItem
}
catch [System.Exception]
{
Write-Verbose -Verbose "Failed to add $RsatItem to Windows"
Write-Warning -Message $_.Exception.Message ; break
}
}
else {
Write-Verbose -Verbose "$RsatItem seems to be installed already"
}
}
if ($PSBoundParameters["Uninstall"]) {
Write-Verbose -Verbose "Script is running with -Uninstall parameter. Uninstalling all RSAT features"
# Querying for installed RSAT features first time
$Installed = Get-WindowsCapability -Online | Where-Object {$_.Name -like "Rsat*" -AND $_.State -eq "Installed" -AND $_.Name -notlike "Rsat.ServerManager*" -AND $_.Name -notlike "Rsat.GroupPolicy*" -AND $_.Name -notlike "Rsat.ActiveDirectory*"}
if ($Installed -ne $null) {
Write-Verbose -Verbose "Uninstalling the first round of RSAT features"
# Uninstalling first round of RSAT features - some features seems to be locked until others are uninstalled first
foreach ($Item in $Installed) {
$RsatItem = $Item.Name
Write-Verbose -Verbose "Uninstalling $RsatItem from Windows"
try {
Remove-WindowsCapability -Name $RsatItem -Online
}
catch [System.Exception]
{
Write-Verbose -Verbose "Failed to uninstall $RsatItem from Windows"
Write-Warning -Message $_.Exception.Message
}
}
}
# Querying for installed RSAT features second time
$Installed = Get-WindowsCapability -Online | Where-Object {$_.Name -like "Rsat*" -AND $_.State -eq "Installed"}
if ($Installed -ne $null) {
Write-Verbose -Verbose "Uninstalling the second round of RSAT features"
# Uninstalling second round of RSAT features
foreach ($Item in $Installed) {
$RsatItem = $Item.Name
Write-Verbose -Verbose "Uninstalling $RsatItem from Windows"
try {
Remove-WindowsCapability -Name $RsatItem -Online
}
catch [System.Exception]
{
Write-Verbose -Verbose "Failed to remove $RsatItem from Windows"
Write-Warning -Message $_.Exception.Message
}
}
}
else {
Write-Verbose -Verbose "All RSAT features seems to be uninstalled already"
}
}
}
else {
Write-Warning -Message "Not running correct Windows 10 build: $WindowsBuild"
}