Automate "Remote Server Administration Tools (RSAT)" Deployment Using PowerShell
These days I am working on a script which does a few “Active directory” task for us. This seemed simple but then I found a major hurdle.
Problem:
** **
The script I was creating will be run on newly formatted systems which is having Windows 7 installed. The main problem was that this script will is using few “Active Directory module” cmdlets. And the new installation of windows doesn’t have “RSAT” (remote server Administration Tools) installed by default. So since I didn’t have “ActiveDirectory” module installed then I can’t use the following;
“**get-ADComputer ; get-ADComputerServiceAccount” **cmdlets.
Then I thought there should be way to sort this out. So finally after spending whole day I found a way to do this within my PowerShell Script.
** **
Solution:
** **
The “Active Directory” module only available after installing the “Windows6.1-KB958830-x86-RefreshPkg.msu” package and then enable the “Active Directory Module for windows Powershell” in optional features.
The “Windows6.1-KB958830-x86-RefreshPkg.msu” is a “Microsoft update Standalone Package” and we can install these packages usingwusa.exe {Windows Update Standalone installer}.
So after installation of the “Windows6.1-KB958830-x86-RefreshPkg.msu” we need to enable the “Active Directory Module for windows Powershell” in optional features for this we are using dism.exe { Deployment Image Servicing and Management tool}.
The Script:
** **
- I am placing “Windows6.1-KB958830-x86-RefreshPkg.msu” in a central location so that script the executable from it.
o \soft-server\SoftRes\hotfix
- Normally I copied all the scripts in “c:\tools” folder and if that folder doesn’t exists it create it for us and write a message on screen that “C:\tools” is created.
- $tool = test-Path C:\tools
if ($tool -eq $false ) {new-Item -Name "Tools" -Path c:\ -ItemType Directory; write-Host " folder "C:\Tools" created" -ForegroundColor Green }
- Now it check if “**Windows6.1-KB958830-x86-RefreshPkg.msu” **file in exists in “C:\tools” folder and if it doesn’t exists it will copy the file from our central share folder \soft-server\SoftRes\hotfix
o hotfix = "Windows6.1-KB958830-x86-RefreshPkg.msu"
if ($testpath -eq $false) { Copy-Item \dc3-del\PublicShare\hotfix c:\tools\
Write-host "Files has Copied Sucessfully, Now I am going to install the HOTFIX." -ForegroundColor RED
}
- After copy the file from server it will install the files using wusa.exe
- & wusa.exe "c:\tools\hotfix" /quiet | out-null
- After the installation finishes it will enable the “Active Directory PowerShell Module” feature in “windows Optional feature” using DISM
- & dism.exe /Online /Enable-Feature /FeatureName:RemoteServerAdministrationTools /FeatureName:RemoteServerAdministrationTools-Roles /FeatureName:RemoteServerAdministrationTools-Roles-AD /FeatureName:RemoteServerAdministrationTools-Roles-AD-Powershell | Out-Null
Download the script from here : http://dl.dropbox.com/u/17858935/RSAT_Deployment.zip
:::::::::::::::::::::::::::::::;; Start of the script ############
$hotfix = "Windows6.1-KB958830-x86-RefreshPkg.msu"
$testpath = test-path -path "c:\tools\hotfix"
$tool = test-Path C:\tools
if ($tool -eq $false ) {new-Item -Name "Tools" -Path c:\ -ItemType Directory; write-Host " folder "C:\Tools" created" -ForegroundColor Green }
if ($testpath -eq $false) { Copy-Item \soft-server\SoftRes\hotfix c:\tools\
Write-host "Files has Copied Sucessfully, Now I am going to install the HOTFIX." -ForegroundColor RED
}
Write-Host "Installing Remote Server Administration Tools...... " -ForegroundColor Yellow
& wusa.exe "c:\tools\hotfix" /quiet | out-null
Write-Host "HotFix Installed, lets enable the Active Directory Features in "Optional Features"" -ForegroundColor "Green"
& dism.exe /Online /Enable-Feature /FeatureName:RemoteServerAdministrationTools /FeatureName:RemoteServerAdministrationTools-Roles /FeatureName:RemoteServerAdministrationTools-Roles-AD /FeatureName:RemoteServerAdministrationTools-Roles-AD-Powershell | Out-Null
Write-Host "Lets Import the Active directory PowerShell Module Now.." -BackgroundColor Green -ForegroundColor Blue
Import-Module ActiveDirectory
write-Host "Module successfully Imported" -ForegroundColor Red -BackgroundColor White
########## End of the Script ##############
Download the script from here : http://dl.dropbox.com/u/17858935/RSAT_Deployment.zip
Screenshots:
http://lh4.ggpht.com/-x6NJ6Sa70vo/TzlADKxSJxI/AAAAAAAACR0/I3o723eOMFo/13-02-2012%25252020-41-20_thumb%25255B1%25255D.png?imgmax=800
Note: I tested this script on Windows 7 machine and it works perfectly for me . you can download installation file of "Windows6.1-KB958830-x86-RefreshPkg.msu" from here http://www.microsoft.com/download/en/details.aspx?id=7887. Also this is a simple static script no error checking is enable in it.
Thanks for viewing
Aman Dhally
http://lh5.ggpht.com/-FP9wZCMZcgg/TzlAE2Y8cxI/AAAAAAAACSE/lcQ3GrqI5rQ/messenger_freak_adp1%252520%25252830%252529_thumb.gif?imgmax=800