Active Directory Powershell-Modul aktualisieren

1. April 2019

Mit den passenden Powershell-Skripts sparen sich die Systembetreuer Zeit und Nerven. Besonders wenn es darum geht, unterschiedliche Operationen auf einer Vielzahl an Systemen durchzuführen.

Möchten die Administratoren die Powershell (PS) unter Windows 10 auf den aktuellen Stand bringen, muss im ersten Schritt das passende PS-Modul heruntergeladen werden. Im nächsten Schritt wird in der Regel RSAT (Remote Server Administration Tools) installiert und aktiviert, um danach die Hilfefunktion für das AD-Modul auf den aktuellen Stand gebracht. Anstatt dies manuell abzuarbeiten, lässt sich auch ein entsprechendes Skript aus der Technet-Galerie einsetzten. Dabei werden folgende Punkte nacheinander abgearbeitet:

  • Find and download the CPU-architecture-appropriate Windows 10 RSAT package (Remote Server Administration Tools)
  • Install the RSAT
  • Enable the Active Directory PowerShell feature
  • Update-Help for the AD module

Dabei wird das Skript in der aktuell installierten S-Version ausgeführt, entweder in einem PS-Kommandozeilenfenster, oder beispielsweise auch mit Hilfe der ISE (Integrated Scripting Environment):

1#requires -RunAsAdministrator
2 
3 
4 
5<#-----------------------------------------------------------------------------
6 
7Ashley McGlone, Microsoft Premier Field Engineer
8 
10 
11February 2016
12 
13Install-ADModule
14 
15For Windows 10 performs the following tasks:
16 
17- Downloads and installs Windows 10 RSAT for the appropriate system architecture
18 
19- Enables the RSAT AD PowerShell feature
20 
21- Updates help for the AD module
22 
23- Displays validation output
24 
25-------------------------------------------------------------------------------
26 
27LEGAL DISCLAIMER
28 
29This Sample Code is provided for the purpose of illustration only and is not
30 
31intended to be used in a production environment.  THIS SAMPLE CODE AND ANY
32 
33RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
34 
35EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
36 
37MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.  We grant You a
38 
39nonexclusive, royalty-free right to use and modify the Sample Code and to
40 
41reproduce and distribute the object code form of the Sample Code, provided
42 
43that You agree: (i) to not use Our name, logo, or trademarks to market Your
44 
45software product in which the Sample Code is embedded; (ii) to include a valid
46 
47copyright notice on Your software product in which the Sample Code is embedded;
48 
49and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and
50 
51against any claims or lawsuits, including attorneys’ fees, that arise or result
52 
53from the use or distribution of the Sample Code.
54 
55 
56 
57This posting is provided "AS IS" with no warranties, and confers no rights. Use
58 
59of included script samples are subject to the terms specified
60 
62 
63-----------------------------------------------------------------------------#>
64 
65 
66 
67 
68 
69<#
70 
71.SYNOPSIS
72 
73Installs the AD PowerShell module from RSAT for Windows 10
74 
75.DESCRIPTION
76 
77Performs the following tasks:
78 
79- Downloads and installs Windows 10 RSAT for the appropriate system architecture
80 
81- Enables the RSAT AD PowerShell feature
82 
83- Updates help for the AD module
84 
85- Displays validation output
86 
87.NOTES
88 
89Requires an elevated PowerShell host.
90 
91 
92 
93Requires an internet connection to download the RSAT install.
94 
95 
96 
97The RSAT hotfix download (<100MB) will be stored in the Downloads
98 
99folder of the user running the script.
100 
101 
102 
103Checks the following before taking action:
104 
105- Is the system running Windows 10?
106 
107- Is the RSAT already installed?
108 
109- Is the AD PowerShell feature already enabled?
110 
111.PARAMETER Test
112 
113Switch parameter to validate the install. Performs the following:
114 
115- Displays the RSAT update file that was downloaded.
116 
117- Confirms the hotfix is installed.
118 
119- Displays help for Get-ADDomain.
120 
121- Run the cmdlets Get-ADDomain.
122 
123.EXAMPLE
124 
125Install-ADModule -Verbose
126 
127.EXAMPLE
128 
129Install-ADModule -Test -Verbose
130 
131#>
132 
133Function Install-ADModule {
134 
135[CmdletBinding()]
136 
137Param(
138 
139[switch]$Test = $false
140 
141)
142 
143 
144 
145If ((Get-CimInstance Win32_OperatingSystem).Caption -like "*Windows 10*") {
146 
147Write-Verbose '---This system is running Windows 10'
148 
149} Else {
150 
151Write-Warning '---This system is not running Windows 10'
152 
153break
154 
155}
156 
157 
158 
159If (Get-HotFix -Id KB2693643 -ErrorAction SilentlyContinue) {
160 
161 
162 
163Write-Verbose '---RSAT for Windows 10 is already installed'
164 
165 
166 
167} Else {
168 
169 
170 
171Write-Verbose '---Downloading RSAT for Windows 10'
172 
173 
174 
175If ((Get-CimInstance Win32_ComputerSystem).SystemType -like "x64*") {
176 
177$dl = 'WindowsTH-KB2693643-x64.msu'
178 
179} Else {
180 
181$dl = 'WindowsTH-KB2693643-x86.msu'
182 
183}
184 
185Write-Verbose "---Hotfix file is $dl"
186 
187 
188 
189Write-Verbose "---$(Get-Date)"
190 
191#Download file sample
192 
194 
196 
197$URL = $BaseURL + $dl
198 
199$Destination = Join-Path -Path $HOME -ChildPath "Downloads\$dl"
200 
201$WebClient = New-Object System.Net.WebClient
202 
203$WebClient.DownloadFile($URL,$Destination)
204 
205$WebClient.Dispose()
206 
207 
208 
209Write-Verbose '---Installing RSAT for Windows 10'
210 
211Write-Verbose "---$(Get-Date)"
212 
214 
215wusa.exe $Destination /quiet /norestart /log:$home\Documents\RSAT.log
216 
217 
218 
219# wusa.exe returns immediately. Loop until install complete.
220 
221do {
222 
223Write-Host "." -NoNewline
224 
225Start-Sleep -Seconds 3
226 
227} until (Get-HotFix -Id KB2693643 -ErrorAction SilentlyContinue)
228 
229Write-Host "."
230 
231Write-Verbose "---$(Get-Date)"
232 
233}
234 
235 
236 
237# The latest versions of the RSAT automatically enable all RSAT features
238 
239If ((Get-WindowsOptionalFeature -Online -FeatureName `
240 
241RSATClient-Roles-AD-Powershell -ErrorAction SilentlyContinue).State `
242 
243-eq 'Enabled') {
244 
245 
246 
247Write-Verbose '---RSAT AD PowerShell already enabled'
248 
249 
250 
251} Else {
252 
253 
254 
255Write-Verbose '---Enabling RSAT AD PowerShell'
256 
257Enable-WindowsOptionalFeature -Online -FeatureName RSATClient-Roles-AD-Powershell
258 
259 
260 
261}
262 
263 
264 
265Write-Verbose '---Downloading help for AD PowerShell'
266 
267Update-Help -Module ActiveDirectory -Verbose -Force
268 
269 
270 
271Write-Verbose '---ActiveDirectory PowerShell module install complete.'
272 
273 
274 
275# Verify
276 
277If ($Test) {
278 
279Write-Verbose '---Validating AD PowerShell install'
280 
281dir (Join-Path -Path $HOME -ChildPath Downloads\*msu)
282 
283Get-HotFix -Id KB2693643
284 
285Get-Help Get-ADDomain
286 
287Get-ADDomain
288 
289}
290 
291}
292 
293 
294 
295Get-Help Install-ADModule -Full
296 
297 
298 
299Install-ADModule -Verbose
300 
301 
302 
303#Install-ADModule -Test -Verbose
304 
305 
306 
307break
308 
309 
310 
311<#
312 
313# Remove
314 
315wusa.exe /uninstall /kb:2693643 /quiet /norestart /log:$home\RSAT.log
316 
317#>

Das Listing ist alternativt auf der entsprechenden Microsoft-Seite im TXT-Format abrufbar, und muss mit Administrator-berechtigungen ausgeführt werden.

Florian Huttenloher

 

Lesen Sie auch