Exporting All AD Computers list by OU using PowerShell

Exporting All AD Computers by OU using PowerShell


When you run this script, it generates a CSV file containing the following details for all computers in the specified OU:

  • DistinguishedName: The full Active Directory path of the computer object.

  • Name: The hostname of the computer.

  • ObjectGUID: The unique identifier for the computer in AD.

  • OperatingSystem: The installed OS on the machine.

  • OperatingSystemVersion: The version of the installed OS.

  • LastLogonDate: The last recorded logon date of the computer.

The output file C:\Reports\AllComputers.csv can be opened in Excel or any text editor for further analysis.

-------------------------------------------------------------------------------------------------------------

# Define the Organizational Unit (OU) to search

$OU = "DC=CCM,DC=LOCAL"  # Change this if you want to target a specific OU


# Retrieve all computers within the specified OU and export to CSV

Get-ADComputer -SearchBase $OU -Filter * `

    -Properties DistinguishedName, Name, ObjectGUID, OperatingSystem, OperatingSystemVersion, LastLogonDate |

Select-Object DistinguishedName, Name, ObjectGUID, OperatingSystem, OperatingSystemVersion, LastLogonDate |

Export-Csv -Path "C:\Reports\AllComputers.csv" -NoTypeInformation


Write-Host "Report generated: C:\Reports\AllComputers.csv"

Popular Posts

Windows 11 24H2 Upgrade using Intune Feature Updates Policy

Deploying a Script through Intune to a Linux PC

Removing Obsolete Computer Records from Active Directory Using PowerShell (Only Windows Client Versions)

Deleting Registry.pol and Forcing Group Policy Update Using a Batch File - Deploy through SCCM