Export AD Computers To CSV Using PowerShell - MorganTechSpace

Skip to content Menu We can generate and export Active Directory computers report to CSV file using powershell cmdlets Get-ADComputer and Export-CSV. The Get-ADComputer cmdlet supports SQL like filter and LDAP filter to filter AD Computers.

Find and List AD Computers

The following powershell script list the selected properties of all computers.

Import-Module ActiveDirectory Get-ADComputer -Filter * -Properties * | Select -Property Name,operatingSystem,@{Name="LastLogon"; Expression={[DateTime]::FromFileTime($_.lastLogon).ToString()}}

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 script select computers whose OperatingSystem contains the text ‘Server 2008 R2’.

Import-Module ActiveDirectory Get-ADComputer -Filter 'OperatingSystem -like "*Server 2008 R2*"' -Properties * | Select -Property Name,operatingSystem,@{Name="LastLogon"; Expression={[DateTime]::FromFileTime($_.lastLogon).ToString()}}

Apply LDAP Filter to get specific set of AD computers:

If your are familiar with LDAP filter, instead of normal filter, you can also use LDAP filter with more flexibility to filter Active Directory computers. The below script select all the computers whose OperatingSystem contains the text ‘Server 2008 R2’.

Import-Module ActiveDirectory Get-ADComputer -LDAPFilter '(OperatingSystem=*Server 2008 R2*)' -Properties * | Select -Property Name,operatingSystem,@{Name="LastLogon"; Expression={[DateTime]::FromFileTime($_.lastLogon).ToString()}}

Export AD Computers to CSV file

We can generate and export all computer details to CSV file by using Export-CSV cmdlet. You can add more attributes in Select -Property field to export more AD attributes.

Import-Module ActiveDirectory Get-ADComputer -Filter 'OperatingSystem -like "*Server 2008 R2*"' -Properties * | Select -Property Name,operatingSystem,@{Name="LastLogon"; Expression={[DateTime]::FromFileTime($_.lastLogon).ToString()}} | # Export AD Computer Report to CSV file Export-CSV "C:\ADComputers.csv" -NoTypeInformation -Encoding UTF8

Export AD Computers from Specific OU

We can set target OU scope by using the parameter SearchBase. The following powershell script select all the Windows Server 2008 R2 AD computers from the Organization Unit ‘TestOU’ and export it to CSV file.

Import-Module ActiveDirectory Get-ADComputer -SearchBase "OU=TestOU,DC=TestDomain,DC=Local"` -Filter 'OperatingSystem -like "*Windows Server 2008 R2*"' -Properties * | Select -Property Name,operatingSystem,@{Name="LastLogon"; Expression={[DateTime]::FromFileTime($_.lastLogon).ToString()}} | # Export AD Computers to CSV file Export-CSV "C:\ADComputers.csv" -NoTypeInformation -Encoding UTF8

CSV output of AD Computers Report:

Powershell - Export Active Directory Computers to CSV

Share this:

  • Facebook
  • X

Related Posts

  • Export AD Users to CSV using PowerShell
  • Export AD Users to CSV using Powershell Script
  • Export Disabled AD Users to CSV with Powershell
  • Export AD Group Members to CSV using Powershell
  • Export Locked Out AD Accounts to CSV 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 To Csv