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"