Drew Robinson's Blog

Azure, Powershell and Security things

Installing Remote Server Admin Tools (RSAT) via Powershell

I reload my boxes frequently, also I have a few installations that are enrolled in Windows Insider, which installs new builds frequently. The insider build update cycle will reset existing updates including Remote Server Tools (Active Directory Powershell, Active Directory Users and Computer, etc) .. Drew is not one to download and install things over and over again.. so so created the following  PS code.

Following PS code will install server admin tools on ‘Windows Server*’ and Remote Server Administration Tools (RSAT) Windows 10 (x86/x64). 

CODE:

 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
#Requires -RunAsAdministrator

$web = Invoke-WebRequest https://www.microsoft.com/en-us/download/confirmation.aspx?id=45520

$MachineOS= (Get-WmiObject Win32_OperatingSystem).Name

#Check for Windows Server 2012 R2
IF($MachineOS -like "*Microsoft Windows Server*") {
    
    Add-WindowsFeature RSAT-AD-PowerShell
    Break}

        IF ($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64"){
            Write-host "x64 Detected" -foregroundcolor yellow
            $Link=(($web.AllElements |where class -eq "multifile-failover-url").innerhtml[0].split(" ")|select-string href).tostring().replace("href=","").trim('"')
            }ELSE{
            Write-host "x86 Detected" -forgroundcolor yellow
            $Link=(($web.AllElements |where class -eq "multifile-failover-url").innerhtml[1].split(" ")|select-string href).tostring().replace("href=","").trim('"')
            }

$DLPath= ($ENV:USERPROFILE) + "\Downloads\" + ($link.split("/")[8])

Write-Host "Downloading RSAT MSU file" -foregroundcolor yellow
Start-BitsTransfer -Source $Link -Destination $DLPath

$Authenticatefile=Get-AuthenticodeSignature $DLPath


$WusaArguments = $DLPath + " /quiet"
if($Authenticatefile.status -ne "valid") {write-host "Can't confirm download, exiting";break}
Write-host "Installing RSAT for Windows 10 - please wait" -foregroundcolor yellow
Start-Process -FilePath "C:\Windows\System32\wusa.exe" -ArgumentList $WusaArguments -Wait