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 91011121314151617181920212223242526272829303132
 #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 R2IF($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 yellowStart-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 yellowStart-Process -FilePath "C:\Windows\System32\wusa.exe" -ArgumentList $WusaArguments -Wait

#Update,  W10 build 17682 includes RSAT on demand

#Example, List all RSAT

Get-WindowsCapability -Online | ? Name -like 'RSAT.*'

#Example, Install  Directory Services

Get-WindowsCapability -Online | ? Name -like Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 |Add-WindowsCapability -Online

#Example, install complete RSAT

Get-WindowsCapability -Online | ? Name -like 'RSAT.*' | Add-WindowsCapability -Online