Get List Of All Computers In AD Using PowerShell - MorganTechSpace

Skip to content Menu We can get a list of all computers in Active Directory using the Powershell cmdlet Get-ADComputer. The Get-ADComputer cmdlet supports SQL like filter and LDAP filter to filter AD computers. You can select any attribute that supported in Active Directory and it also supports Extended Properties like Enabled,LastLogonDate,etc…

Before proceed run the following command to import Active Directory module.

Import-Module ActiveDirectory

The following command find and list all the available computers in Active Directory.

Get-ADComputer -Filter * -Properties * | Select -Property Name,DNSHostName,Enabled,LastLogonDate

Export all AD Computers to CSV file

You can also export the computer list to csv file by using the powershell cmdlet Export-CSV.

Get-ADComputer -Filter * -Properties * | Select -Property Name,DNSHostName,Enabled,LastLogonDate | Export-CSV "C:\AllComputers.csv" -NoTypeInformation -Encoding UTF8

Get all computers in OU

We can also find and get a list of AD computers from particular OU by setting target OU scope by using the parameter SearchBase. The following powershell command select all AD computers from the Organization Unit ‘TestOU‘ and export it to CSV file.

Get-ADComputer -Filter * -SearchBase "OU=TestOU,DC=TestDomain,DC=com" -Properties * | Select -Property Name,DNSHostName,Enabled,LastLogonDate | Export-CSV "C:\AllComputersInOU.csv" -NoTypeInformation -Encoding UTF8

Apply SQL Like filter to get specific computers

The Get-ADComputer cmdlet supports SQL like filter, users who are not familiar with LDAP filter can easily use this filter to get only specific set of AD computers. The following powershell commnd export all computers based on operatingSystem that contains the value ‘Windows 7’.

Get-ADComputer -Filter 'operatingSystem -like "*Windows 7*"' -Properties * | Select -Property Name,DNSHostName,operatingSystem,LastLogonDate | Export-CSV "C:\Windows7Computers.csv" -NoTypeInformation -Encoding UTF8

Apply LDAP Filter to get specific computers

If your are familiar with LDAP filter, instead of normal filter, you can also use LDAP filter in Get-ADComputer cmdlet with more flexibility to filter Active Directory computers. The following powershell commnd get list of computers based on operatingSystem that contains the value ‘Windows 7’.

Get-ADComputer -LDAPFilter '(operatingSystem=*Windows 7*)' -Properties * | Select -Property Name,DNSHostName,operatingSystem,LastLogonDate | Export-CSV "C:\Windows7Computers.csv" -NoTypeInformation -Encoding UTF8

Share this:

  • Facebook
  • X

Related Posts

  • Get AD Computer Description using Powershell
  • Get all computers from OU in AD using PowerShell
  • Get AD User Home Directory using PowerShell
  • Export AD Computers to CSV using PowerShell
  • Find AD Domain Controllers using Powershell
Advertisement

Leave a Comment Cancel reply

Comment

Name Email Website

Save my name, email, and website in this browser for the next time I comment.

Δ

Categories

  • Powershell
  • Microsoft 365
  • Azure AD
  • SharePoint Online
  • Exchange Online
  • Microsoft Teams
  • Office 365 Groups
  • Active Directory
  • Microsoft Graph
  • PnP-PowerShell
  • CSOM

Recent Posts

  • Get Azure AD (Entra ID) App-Only Access Token with PowerShell
  • Working with REST API in PowerShell using Invoke-RestMethod
  • M365 User SignIn Activity – Neither tenant is B2C or tenant doesn’t have premium license
  • How to Join or Concatenate String and Number Using PowerShell
  • Find Location and County by IP Address with PowerShell
  • Microsoft 365
  • Azure AD
  • SharePoint Online
  • Exchange Online
  • Microsoft Teams
  • Microsoft 365 Groups
  • OneDrive for Business
  • Azure AD Authentication
  • Active Directory
  • Exchange Server
  • PowerShell
  • PnP PowerShell
  • Microsoft Graph
  • CSOM
  • VBScript

Follow us

  • Facebook
  • Twitter
DMCA.com Protection Status

Tag » Active Directory Export Computer List Operating System