Home > Active-Directory > Get-AD.ps1

Get-AD.ps1

Get-AD.ps1

This Script gets Information About Objects in Active-Directory. It’s got a few Parameters and Switches that allows us to specify what to search for and how to Return the objects found. You can choose which information to return through the Property parameter, you can Save the Information to a Csv file, You can return a System.DirectoryServices.DirectoryEntry Object that you can work with through PowerShell.. you can do lots of things.

Parameters:

  • -Domain Name of the Domain (Required)
  • -OU Name of Organizational Unit (Optional)
  • -User Name of the User (Optional)
  • -Group Name of the Group (Optional)
  • -Computer Name of the Computer (Optional)
  • -Filter Filter on Specified Criteria, default is name (optional)
  • -CustomFilter Create A custom SearchFilter (optional)
  • -CustomAll Create A Custom SerachFilter, searches for All Objects (optional)
  • -Property Specify one or more Properties to Return (Optional)
  • -ToCsv Saves the Output to a Csv File (Optional)
  • -ToObject Returns a System.DirectoryServices.DirectoryEntry Object (optional)
  • -IncreasePageSize Exceeds the default limit of 1000 Objects (optional)
  • -help Prints the HelpFile (Optional)

Here are a few Example Scenarios on running The Script

You want to display a HelpText about the Script


PS > Get-AD.ps1 -Help

You want to Display Domain Information About Your Domain


PS > Get-AD.ps1 -Domain apa.corp

You want to Connect to a Domain and store the Object in a Variable


PS > $Domain = Get-AD.ps1 -Domain apa.corp -ToObject

You want to retrieve All OrganizationalUnits in your Domain and store their distiguishedName in a Csv file


PS > Get-AD.ps1 -Domain apa.corp -OU AllOU -Property distinguishedName -ToCsv C:MyFolderMyOUFile.csv

You want to Get all Users and display their name and mail in your PowerShell Session


PS > Get-AD.ps1 -Domain apa.corp -User AllUsers -Property cn, mail

You want to Find a User, but you only know the Users sAMAccountName


PS > Get-AD.ps1 -Domain apa.corp -User User1 -Filter sAMAccountName -Property cn, mail

You want to Create a Csv File with all Computers in your domain


PS > Get-AD.ps1 -Domain apa.corp -Computer AllCOmputers -Property Name -ToCsv C:\MyFolderMyOUFile.csv

You can Download the Script here

Rating 3.00 out of 5
[?]
  1. No comments yet.
  1. No trackbacks yet.

Spam Protection by WP-SpamFree