This script will retrieve and display all Active Directory computers that are active (i.e., enabled). You can further customize the script to include additional properties or filter criteria as needed.
# Import the Active Directory module
Import-Module ActiveDirectory
# Retrieve all Active Directory computers that are enabled
$computers = Get-ADComputer -Filter {Enabled -eq $true}
# Display the computers
$computers
- Import-Module ActiveDirectory: This line imports the Active Directory module, which provides cmdlets for managing Active Directory objects.
- Get-ADComputer: This cmdlet is used to retrieve Active Directory computers. We specify a filter using the
-Filterparameter to narrow down the results. - {Enabled -eq $true}: This is the filter expression. We’re filtering computers where the
Enabledproperty is equal to$true, indicating they are active. - $computers: This variable stores the result of the
Get-ADComputercmdlet, which contains all the Active Directory computers that meet the specified filter criteria. - $computers: Finally, we display the computers by outputting the contents of the
$computersvariable.
For an advanced version of this PowerShell Script that queries every Active Computer in the Active Directory Domain and exports to CSV, Checkout this link
