PowerShell: Install RSAT

function runasAdministrator{
# Ensure that script is ran in the context of an Administrator
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

# Get the security principal for the Administrator role

# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
# We are running "as Administrator" - so change the title and background color to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
$Host.UI.RawUI.BackgroundColor = "Black"
# Relaunch script to run as Administrator
# Create a new process object that starts PowerShell
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";

# Specify the current script path and name as a parameter
$newProcess.Arguments = $myInvocation.MyCommand.Definition;

# Indicate that the process should be elevated
$newProcess.Verb = "runas";

# Start the new process

# Exit from the current, unelevated, process

function installRSAT{
# This function currently only accounts for Windows 10 and Server OS'es. Previous versions of Windows will be ignored
$rsat1709 = "https://download.microsoft.com/download/1/D/8/1D8B5022-5477-4B9A-8104-6A71FF9D98AB/WindowsTH-RSAT_WS_1709-x64.msu"
$rsat1803 = "https://download.microsoft.com/download/1/D/8/1D8B5022-5477-4B9A-8104-6A71FF9D98AB/WindowsTH-RSAT_WS_1803-x64.msu"
$rsatWs2016 = "https://download.microsoft.com/download/1/D/8/1D8B5022-5477-4B9A-8104-6A71FF9D98AB/WindowsTH-RSAT_WS2016-x64.msu"

$osVersionNumber= (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ReleaseId).ReleaseId
$osName=(Get-WmiObject Win32_OperatingSystem).Name
switch ($osVersionNumber){
1709 {$link=$rsat1709}
1803 {$link=$rsat1803}

# If OS is Windows Server, then install RSAT using a different method
if ($osName -like "*Microsoft Windows Server*") {
Add-WindowsFeature RSAT-AD-PowerShell

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

Write-Host "Downloading RSAT..." -foregroundcolor blue
Start-BitsTransfer -Source $link -Destination $destination

$fileCheck=Get-AuthenticodeSignature $destination
if($fileCheck.status -ne "valid") {write-host "Expected file doesn't exist. Please try again...";break}

$wusaCommand = $destination + " /quiet"
Write-host "Installing RSAT for Windows 10 - please wait..." -foregroundcolor blue
Start-Process -FilePath "C:\Windows\System32\wusa.exe" -ArgumentList $wusaCommand -Wait


Leave a Reply

Your email address will not be published. Required fields are marked *