PowerShell script to silently install RSAT 2008 R2 SP1

I often re-image my machine – that way I know my SCCM OSD is working properly and has the most recent “secondary apps” (Reader,Flash,FireFox . . .). Because I am always re-imaging, I like to automate installing the software I always need like Remote Server Administration Tools – RSAT. I wanted a function to install the software and automatically add all the features. Below is that script:

function Install-RSAT {
$ScriptPath = "\\server\sahre\path\to\RAST\installers\"
Set-Location $ScriptPath

$os=(Get-WMIObject win32_operatingsystem).OSArchitecture
$sp=(Get-WmiObject Win32_OperatingSystem).CSDVersion
if (($os -eq "64-bit") -and ($sp -eq "")) {$files = get-childitem -recurse -filter amd64*.msu}
if (($os -eq "32-bit") -and ($sp -eq "")) {$files = get-childitem -recurse -filter x86*.msu}
if (($os -eq "64-bit") -and ($sp -eq "Service Pack 1")) {$files = get-childitem -recurse -filter *KB958830*amd64*.msu}
if (($os -eq "32-bit") -and ($sp -eq "Service Pack 1")) {$files = get-childitem -recurse -filter *KB958830*x86*.msu}

foreach ($file in $files)
{
Start-Process -wait -FilePath "C:\WINDOWS\SYSTEM32\wusa.exe" -ArgumentList "$file.FullName /quiet /norestart"
}

DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-AD /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-AD-DS /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-AD-DS-SnapIns /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-AD-DS-AdministrativeCenter /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-AD-DS-NIS /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-AD-LDS /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-AD-Powershell /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-ServerManager /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-CertificateServices /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-CertificateServices-CA /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-CertificateServices-OnlineResponder /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-DHCP /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-DNS /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-FileServices /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-FileServices-Dfs /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-FileServices-Fsrm /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-FileServices-StorageMgmt /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-HyperV /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Roles-RDS /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-BitLocker /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-Clustering /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-GP /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-LoadBalancing /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-SmtpServer /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-StorageExplorer /Quiet /NoRestart
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-StorageManager
DISM /online /Enable-Feature /FeatureName:RemoteServerAdministrationTools-Features-Wsrm
}

5 Responses to PowerShell script to silently install RSAT 2008 R2 SP1

  1. Roi February 15, 2012 at 10:20 am #

    Hi,

    this is only working for Windows 7 machines right?
    I tried to do this for the server in it’s install.wim but this features didn’t show up in the feature list.
    Any idea how I could enable the rsat tools in the wim file?

    Thanks for your help!

    Roi

  2. jbmurphy February 16, 2012 at 12:34 pm #

    Yes, this is only for Windows 7. Not sure how to add them to the wim. I just run the commands after I setup the server. Thanks for taking the time to comment.

  3. Roi March 26, 2012 at 2:16 am #

    You would mount your wim file with:
    DISM.exe /Mount-Wim /WimFile:C:\test\images\myimage.wim /index:1 /MountDir:C:\test\offline

    To know with index you to use:

    DISM.exe /Get-WimInfo /WimFile:C:\test\images\myimage.wim

    You can then execute your commands to the offline image:
    DISM.exe /Image:C:\test\offline /Enable-Feature /FeatureName:RemoteServerAdministrationTools…..

    You can also add drivers or patches to the wim. I use the wsus-offline tool to get all patches and put them into the wim file.

    DISM.exe /image:C:\test\offline /LogPath:AddPackage.log /Add-Package /PackagePath:C:\packages\*

    Then you need to commit and unmount the file again.

    DISM.exe /Unmount-Wim /MountDir:C:\test\offline /commit

    You’re done.
    You have now a fully patched and feature activated w7 image.
    For example you could add and enable virtual pc with this method to the image.
    I always install w7 from a usb stick or a deployment server. This is all the same file. So there is no real need for scripts for that.

  4. jbmurphy March 26, 2012 at 10:06 am #

    I have never tried this. I usually just allow patches to be applied via WSUS. Although if we move to a VDI solution, I will look into this method!
    Thanks for taking the time to comment.

  5. rrathbun March 15, 2013 at 12:03 am #

    JB,

    Check out “ServiceImage.PS1” on the Microsoft Script Repository. You can add RSAT and all applicable patches to the OS before installation

    DISM also allows you to add the product key and unnattend.xml allows you to many more fancy things like change the default administrator account name – use MDT 2012 sp1 to do the above tasks (much easier).

    One warning, certain KB’s do not permit offline installs. DISM will show an error and tell you the patch needs to be installed online. I just add those patches to the installation sequence when the OS is up and running.

    Injecting RSAT and all the OS patches saves tons of time…

    Enjoy!