0% found this document useful (0 votes)
18 views3 pages

Get Ad Computers

Uploaded by

tvsinfinity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Get Ad Computers

Uploaded by

tvsinfinity
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

To retrieve a list of computers from Active Directory (AD) using

PowerShell, you can use the Get-ADComputer cmdlet. This cmdlet


allows you to query computers in your Active Directory environment.
Basic Command to Get All Computers in Active Directory
powershell
Copy code
# Import the Active Directory module (if not already loaded)
Import-Module ActiveDirectory

# Get all computers in Active Directory


Get-ADComputer -Filter *
Explanation:
 Get-ADComputer: This cmdlet is used to retrieve information
about computers in Active Directory.
 -Filter *: The * symbol is a wildcard that means "retrieve all
computers." You can replace it with specific filter criteria (e.g., a
particular name or attribute) to narrow down your search.
Retrieve Specific Properties
You may want to retrieve specific properties of the computers, such as
the computer name, operating system, and IP address. You can use the
Select-Object cmdlet to display these attributes.
powershell
Copy code
# Get all computers and display selected properties (e.g., Name,
OperatingSystem, LastLogonDate)
Get-ADComputer -Filter * -Property Name, OperatingSystem,
LastLogonDate |
Select-Object Name, OperatingSystem, LastLogonDate
Explanation:
 -Property: Specifies which properties you want to retrieve. In this
case, Name, OperatingSystem, and LastLogonDate.
 Select-Object: This cmdlet is used to format the output by
selecting specific properties to display.
Get Computers in a Specific Organizational Unit (OU)
If you want to retrieve computers from a specific Organizational Unit
(OU), you can specify the -SearchBase parameter:
powershell
Copy code
# Get all computers from a specific OU
$ou = "OU=Computers,DC=domain,DC=com" # Modify with your OU
path
Get-ADComputer -Filter * -SearchBase $ou
Explanation:
 -SearchBase: Specifies the distinguished name (DN) of the OU to
search within. Replace $ou with the actual DN of the desired OU.
Filter Based on Specific Criteria
You can filter computers based on certain criteria. For example, to get
only computers that have the word "Server" in their name:
powershell
Copy code
# Get all computers whose names contain 'Server'
Get-ADComputer -Filter 'Name -like "*Server*"' -Property Name |
Select-Object Name
Explanation:
 -Filter 'Name -like "*Server*"': Filters computers by name using
the -like operator to find computers whose names contain the
word "Server."
Get Computers in Specific Domain
If you're querying computers from a different domain or forest, you can
use the -Server parameter to specify the domain controller:
powershell
Copy code
# Get all computers in a different domain
Get-ADComputer -Filter * -Server "DC.domain.com"
Export Results to a CSV File
To export the list of computers to a CSV file for reporting or analysis,
you can use the Export-Csv cmdlet:
powershell
Copy code
# Export list of computers to a CSV file
Get-ADComputer -Filter * -Property Name, OperatingSystem |
Select-Object Name, OperatingSystem |
Export-Csv -Path "C:\AD_Computers.csv" -NoTypeInformation
Explanation:
 Export-Csv: This cmdlet exports the results to a CSV file, which
you can open in Excel or analyze further.

Important Notes:
1. Permissions: You must have the necessary permissions to query
Active Directory. Typically, this would be read access to the
domain or membership in an administrative group.
2. Performance: If your AD environment is large, running these
commands can return a large number of results. Be mindful of
performance when running complex queries.
3. Filter Customization: You can adjust the filter to meet your
specific needs. For example, use properties like OperatingSystem
or LastLogonDate to refine your search.
Let me know if you need more help with these queries or have
additional requirements!
4o mini

You might also like