Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Friday, October 1, 2010

How to import the Active Directory modules into PowerShell.

In PowerShell V1, I was a bit disapointed with the lack of Active Directory support built into PowerShell. With V2 and the RSAT (Remote Server Administration Tools), you have much greater management capability of your AD environment with PowerShell.

The first step is to get your PowerShell configured for AD. On a Windows Server 2008 R2 domain controller, this is easy. Just click Start / Windows PowerShell Modules. That will bring up a PowerShell console with all the new goodies loaded up. Now, what about the ISE?

To load the AD Modules up in the ISE, I have a small script that I use. I just run it and I'm ready to go. You can also include this as a function in your own scripts to avoid having to run a supporting script.

<#

===========================================
Script Name: ImportAD.ps1
Author: Jason A. Yoder, MCT
Company: MCTExpert, Inc.
Website: www.MCTExpert.com
Blogsite: www.MCTExpert.blogspot.com

Date: 2010AUG24

Script Purpose:
install the Active Directory components of PowerShell.

Requirements:
- PowerShell V2
- Remote Server Administration Tools
- A Windows domain
#>

# Main Code ===================================

Import-Module ServerManager
Add-WindowsFeature RSAT-AD-PowerShell
Import-Module ActiveDirectory

# End Script ===================================

No comments: