Skip to content

Instantly share code, notes, and snippets.

@jwmoss
Created January 2, 2018 19:27
Show Gist options
  • Save jwmoss/0207e9e851bf1c491c31b0f7b820e987 to your computer and use it in GitHub Desktop.
Save jwmoss/0207e9e851bf1c491c31b0f7b820e987 to your computer and use it in GitHub Desktop.
#Requires -RunAsAdministrator
#Adapted from https://blogs.technet.microsoft.com/drew/2016/12/23/installing-remote-server-admin-tools-rsat-via-powershell/
$web = Invoke-WebRequest https://www.microsoft.com/en-us/download/confirmation.aspx?id=45520 -UseBasicParsing
$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.Links.href | Where-Object {$PSitem -like "*RSAT*" -and $PSitem -like "*x64*" -and $PSitem -notlike "*2016*"} | Select-Object -First 1)
}
ELSE {
Write-host "x86 Detected" -forgroundcolor yellow
$Link = ($web.Links.href | Where-Object {$PSitem -like "*RSAT*" -and $PSitem -like "*x86*" -and $PSitem -notlike "*2016*"} | Select-Object -First 1)
}
$DLPath = ($ENV:USERPROFILE) + "\Downloads\" + ($link.split("/")[8])
$Path = ($ENV:USERPROFILE) + "\Downloads\"
Write-Host "Downloading RSAT MSU file" -foregroundcolor yellow
Start-BitsTransfer -Source $Link -Destination $DLPath
$Authenticatefile = Get-AuthenticodeSignature $DLPath
if ($Authenticatefile.status -ne "valid") {write-host "Can't confirm download, exiting"; break}
$1ex = New-Item $Path\ex -ItemType Directory
$2ex = New-Item $Path\ex\ex -ItemType Directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment