HI,
These days I am working on a script which does few “Active directory” task for us. This was seems simple so for but then I have found a major hurdle comes.
Problem:
The script on which I am working will be run on newly formatted system which is having Windows7 installed. The problem was that this script will is using few “Active Directory” cmdlets. And the new installation of windows doesn’t have “RSAT” installed by default. So until or unless I don’t have “ActiveDirectory” module installed till then I can’t use my
“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:
o \\soft-server\SoftRes\$hotfix
if ($tool -eq $false ) {new-Item -Name "Tools" -Path c:\ -ItemType Directory; write-Host " folder "C:\Tools" created" -ForegroundColor Green }
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
}
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 ($testpath -eq $false) { Copy-Item \\soft-server\SoftRes\$hotfix c:\tools\
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 ##############
Screenshots:
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
Ed Price - MSFT edited Original. Comment: Title casing