Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Managing Active Directory (AD) is a critical task for systems administrators, and one common task is listing all computer accounts within the AD environment. This can be useful for inventory, auditing, or troubleshooting purposes. In this article, we will explore how to list all computer accounts in Active Directory using PowerShell, a powerful scripting language and command-line shell designed specifically for system administration.
Before you begin, ensure you have:
To perform tasks that interact with Active Directory, you need to run PowerShell as an administrator. Right-click the PowerShell icon and select "Run as administrator."
The Active Directory module provides cmdlets for managing AD. To import the module, run the following command:
Import-Module ActiveDirectory
To list all computer accounts in Active Directory, use the Get-ADComputer
cmdlet. This cmdlet retrieves information about computer objects in AD.
To get a simple list of all computer accounts, run:
Get-ADComputer -Filter *
This command retrieves all computer objects in the domain.
To display specific properties, such as the computer name and operating system, use the -Property
parameter:
Get-ADComputer -Filter * -Property Name, OperatingSystem | Select-Object Name, OperatingSystem
This command filters the results to show only the Name
and OperatingSystem
properties.
To export the list of computer accounts to a CSV file for further analysis, use the Export-Csv
cmdlet:
Get-ADComputer -Filter * -Property Name, OperatingSystem | Select-Object Name, OperatingSystem | Export-Csv -Path "C:\ComputerAccounts.csv" -NoTypeInformation
This command saves the list of computer accounts, including their names and operating systems, to a CSV file located at C:\ComputerAccounts.csv
.
-SearchBase
parameter:
Get-ADComputer -Filter * -SearchBase "OU=Computers,DC=example,DC=com"
-Filter
parameter with a condition:
Get-ADComputer -Filter "OperatingSystem -like '*Windows 10*'"
By following these steps, you can efficiently list and manage computer accounts in your Active Directory environment using PowerShell.