Overview

This is a portable solution to quickly extract properties from Active Directory objects, or to return raw DirectorySearcher output.  You can verify that an account exists, get an e-mail address, or make a quick change to an attribute, all without incurring the overhead or dependencies on the RSAT.

The ActiveDirectory module is well suited for many solutions.  That being said, it incurs a good deal of overhead to load the module, there are dependencies on the RSAT (connectivity to a system with the RSAT), and hitting a legacy domain will require changes

Dependencies

Instructions

PowerShell
Edit|Remove
# dot source the function 
    . "\\Path\To\Get-ADSIObject.ps1" 
 
# Get help for Get-ADSIObject 
    Get-Help Get-ADSIObject -Full 
 
# Find an AD object with the samaccountname jdoe 
    Get-ADSIObject jdoe 
 
# Find an AD object meeting the specified criteria 
    Get-ADSIObject -Query "(&(objectCategory=Group)(samaccountname=domain admins))" 
 
# List all groups at the root of contoso.com 
    Get-ADSIObject -Query "(objectCategory=Group)" -Path contoso.com 
 
# Find an AD object for a few users, extract the mail property only 
    Echo jdoe, cmonster | Get-ADSIObject -ObjectCategory User -property mail | Select -expandproperty mail 
 
# List computer objects starting with c-is- 
    Get-ADSIObject -Query "(&(objectCategory=Computer)(samaccountname=c-is-*))" | Select -ExpandProperty samaccountname 
 
# Get a raw ADSI object you can work with, set the title attribute to 'test' 
    $DirectoryEntry = Get-ADSIObject TESTUSER -as DirectoryEntry 
    $DirectoryEntry.put(‘Title’,’Test’)  
    $DirectoryEntry.setinfo()