Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to List All Computer Accounts in Active Directory Using PowerShell

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.

Prerequisites

Before you begin, ensure you have:

  • Administrative privileges on the domain.
  • PowerShell installed on your Windows machine (preferably PowerShell 5.1 or later).
  • The Active Directory module for Windows PowerShell installed.

Step-by-Step Guide

1. Open PowerShell with Administrative Privileges

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."

2. Import the Active Directory Module

The Active Directory module provides cmdlets for managing AD. To import the module, run the following command:

Import-Module ActiveDirectory

3. List All Computer Accounts

To list all computer accounts in Active Directory, use the Get-ADComputer cmdlet. This cmdlet retrieves information about computer objects in AD.

Example 1: Basic Listing

To get a simple list of all computer accounts, run:

Get-ADComputer -Filter *

This command retrieves all computer objects in the domain.

Example 2: Listing with Specific Properties

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.

Example 3: Exporting the List to a CSV File

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.

Additional Tips

  • Filtering by Organizational Unit (OU): If you want to list computer accounts within a specific OU, use the -SearchBase parameter:
    Get-ADComputer -Filter * -SearchBase "OU=Computers,DC=example,DC=com"
  • Filtering by Operating System: To list computers running a specific operating system, use the -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.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.