PowerShell: How to get Domain-Computers using PowerShell


Get-ADComputer

In a Microsoft Active Directory domain, it's important to know what computers are available and active. PowerShell makes it easy to get a list of computers in the domain by leveraging the Active Directory module.

'Get-ADComputer' is a PowerShell cmdlet used to retrieve information about Active Directory computer objects. This cmdlet is part of the Active Directory PowerShell module and requires administrative privileges to access and query Active Directory.

By default, 'Get-ADComputer' retrieves all computer objects in the current domain, but it can also search for specific computers using a variety of parameters, such as computer name, operating system, or last logon time. The results can be filtered and sorted to provide a customized view of the data.

For example, running 'Get-ADComputer -Filter {OperatingSystem -like "*Windows Server*"} | Select-Object Name, OperatingSystem' would retrieve all computer objects with a Windows Server operating system and display the name and operating system properties for each object in the output.

'Get-ADComputer' is a powerful tool for managing and administering Active Directory computer objects, and it can be used to automate tasks, such as software deployment, security auditing, and inventory management.

Example 1: Get a specific computer that shows all properties
PS C:\> Get-ADComputer -Identity "SRV1" -Properties *

Example 2: Get all computers with a name starting with a particular string
PS C:\> Get-ADComputer -Filter 'Name -like "User01*"' -Properties IPv4Address | FT Name,DNSHostName,IPv4Address -A

Example 3: Gets all computers that have changed their password in the specific time frame
PS C:\> $Date = [DateTime]::Today.AddDays(-1) 
PS C:\> Get-ADComputer -Filter 'PasswordLastSet -ge $Date' -Properties PasswordLastSet | FT Name,PasswordLastSet

Example 4: Get computer accounts in a specific location using an LDAPFilter
PS C:\> Get-ADComputer -LDAPFilter "(name=*laptop*)" -SearchBase "CN=Computers,DC= User01,DC=com" name


Example 5: Get all computer accounts using a filter
PS C:\> Get-ADComputer -Filter *

Example 6: Get all computers with a name starting with Computer01 or Computer02
PS C:\> Get-ADComputer -Filter 'Name -like "Computer01*" -or Name -like "Computer02*"' -Properties IPv4Address | FT Name,DNSHostName,IPv4Address -A

Example 7: Get all computers with a name starting with a string AND password last set before 30 days
PS C:\> $Date = [DateTime]::Today.AddDays(-30)
PS C:\> Get-ADComputer -Filter 'Name -like "Computer01*" -and PasswordLastSet -ge $Date' -Properties IPv4Address | FT Name,DNSHostName,IPv4Address -A

Example 8: Get all Windows Server Computers
PS C:\> Get-ADComputer -Filter 'operatingsystem -like "*server*" -and enabled -eq "true"' ` -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address | Sort-Object -Property Operatingsystem | Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address

Example 9: Get all Windows Client Computer
PS C:\> Get-ADComputer -Filter 'operatingsystem -notlike "*server*" -and enabled -eq "true"' ` -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address | Sort-Object -Property Operatingsystem | Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address




Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad