Get Active Directory Computer with Powershell

The PowerShell cmdlet Get-ADComputer can be used to retrieve the details for a computer account. You can use a filter if required. The usage of this cmdlet is like this:

Import-Module ActiveDirectory
Get-ADComputer -property * -filter { <FILTER GOES HERE> }

If no filter property is provided you will be prompted for the filter when running this cmdlet.

Examples

Some examples on how to use this.

Get computer from IP

If you want to get the computer information for a PC with the IP address 192.168.1.1:

Import-Module ActiveDirectory
$ip = '192.168.1.1'
Get-ADComputer -property * -filter { IPv4Address -eq $ip }

Get computer from name

If you want to get the computer information for a PC with the hostname “MY-PC”:

Import-Module ActiveDirectory
$hostname = 'MY-PC$'
Get-ADComputer -property * -filter { SamAccountName -like $hostname }

Get all computer objects

To get all objects without any filtering:

Import-Module ActiveDirectory
Get-ADComputer -property * -filter { SamAccountName -like "*" }

Leave a Reply

Your email address will not be published. Required fields are marked *