Powershell Guide To Extract Information
Powershell Guide To Extract Information
EXTRACT INFORMATION
Learn how to extract information from the ACTIVE DIRECTORY and how its syntax is applied in POWERSHELL
together with its other features.
A whole available of users will be listed out and the list keeps on going until it collects the final users
in the end. Even when only names are prompt to display to the PowerShell but other info such as
GIVEN NAME, SURNAME, SAM ACCOUNT NAME also appears. If you are only requesting for the
names of the users, use the same syntax but with the addition of SELECT-OBJECT cmdlet typed
after PROPERTIES (*USE THE KEY | TO SEPARATE between Properties and Select-Object to
ensure POWERSHELL understands your request) example:-
Again a whole list of users still appears, this is because the syntax tells PowerShell to show all users
in the directories. If you want a more specific type of info from a specific type of department use the
same syntax but with the addition of -SEARCHBASE cmdlet. This function is to only get information
about the users in an available unit such as users only under IT Department.
*Notice after the SEARCHBASE there is a double quotation which contains a directory. This directory
is where you going to extract data from. Key in the directory between the double quotations.
>OU stands for ORGANIZATIONAL UNIT NAME
>DC stands for THE DOMAIN NAME
*Note that the directories must be accurate to enable PowerShell to search accurately.
Example : SYNTAX : Get-ADUser -Filter * -SearchBase "ou=IT,ou=KEM,
ou=Knowles,dc=Knowles,dc=com" -Properties NAME | SELECT-OBJECT NAME
*Notice PowerShell only extracted users from IT department and the directories was accurate
enabling POWERSHELL to find the directories.
Besides Names, users can also extract multiple attributes such as user department, office, job title
and any other properties at the same time making it a fast excess and fast result to display. Just add
in the Attributes into properties syntax separating each attribute with a , symbol. Same goes to the
select-object syntax.
If you are searching information about 1 user, it can be done by typing the GET-ADUSER syntax
and press Enter. A filter message will appear asking users to filter any kind of attribute but with the
condition of entering the value in it.
Example:-
In the filter, type <attribute> -like value. This is the syntax which should be type in the filter.
<attribute> means the name of the attribute such as NAME, SURNAME, GIVENNAME
value means the value in the attribute
-like is another word for equal to
A closer example:-
*Notice the typed syntax in the filter part. This is the accurate way to extract only one user
information. Try searching for your GIVENNAME in the filter part.
2. FORMAT
Heres an effective method to show all attributes in a single view without messing up the
information extracted. Using a syntax called FORMAT which enables viewers to have a better view
of what they have collected. There are three types of Format which are:
Format-Table (recommended)*
Format-List
Format-wide
This syntax should be included after the Select-Object syntax with a | to separate the format type.
Example : SYNTAX : Get-ADUser -Filter * -SearchBase "ou=IT,ou=KEM,
ou=Knowles,dc=Knowles,dc=com" -Properties NAME, GIVENNAME, SAMACCOUNTNAME | SELECTOBJECT NAME, GIVENNAME, SAMACCOUNTNAME | FORMAT-TABLE
Above is an example of a table format which is highly recommended for better view of users
information. Noted that the attributes listed did appear and is more neat and easy to view. Try
listing the same attributes but this time in different formats.
NOTEPAD
OUT-FILE <directory path><filename.txt> -Encoding utf8
HTML
OUT-FILE <directory path><filename.htm>