It is possible to retrieve Active Directory (AD) information using native powershell commands using the ADSI provider:
$myOU = [adsi]"LDAP://CN=Jdoe,OU=TestOU,DC=ss64,DC=com"
$myOU | Get-Member
However for anything non-trivial, the LDAP commands quickly start to become rather verbose, and you will want to wrap them into a set of functions, scripts or cmdlets. The Quest ActiveRoles Management Shell does all this for you and saves re-inventing the wheel.
After installing, load the Quest snap-in with:
PS C:> Add-PSSnapin Quest.ActiveRoles.ADManagement this will make the following cmdlets available:
Get-QADComputer - Retrieve computer objects that match specified conditions. Connect-QADService - Connect to AD domain controller (or AD LDS) Disconnect-QADService - Disconnect from an AD domain controller Get-QADGroup - Retrieve groups that match specific conditions Set-QADGroup - Modify attributes of group(s) New-QADGroup - Create a new workgroup Get-QADGroupMember - Retrieve members of a group Add-QADGroupMember - Add one or more objects to a group Remove-QADGroupMember - Remove one or more members from a group Get-QADMemberOf - Retrieve group memberships of a particular object Get-QADUser - Retrieve users that match specific conditions Set-QADUser - Modify attributes of a user account New-QADUser - Create a new user account Enable-QADUser - Enable a user account Remove-QADObject - Delete object(s) from Active Directory Rename-QADObject - Rename an object in Active Directory Disable-QADUser - Disable a user account Unlock-QADUser - Unlock a user account Deprovision-QADUser - Deprovision a user account in AD
In addition to the above, Quest provide other cmdlets for managing AD Objects, AD ACLs, Password settings, Object security and Snap-In settings.
An alternative method of retrieving AD information is to call dsquery and store the resulting string in a powershell array variable:
$arrComputerList = $(&dsquery computer -limit 0)|%{$_.Split("=")[1].replace(",OU","").replace(",CN","")}
(from PowershellHell)
Related:
PowerGui Wiki - List of all the Quest cmdlets
Dmitry’s PowerBlog - Examples
.Net Framework 3.5 (Full) - or (Bootstrap) - Required for the Quest Snap-In
Installation tips for .Net 3.5