Enumerating computer accounts

The following code sample enumerates computer accounts located in a specific organizational unit.

ADSI
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the organizational unit
$containerDN = "CN=Computers,DC=domain,DC=com"
$container = $service.OpenObject("Adaxes://$containerDN", $null, $null, 0)

$container.Filter = @("computer")

foreach ($computer in $container)
{
    Write-Host $computer.Get("name")
}
PowerShell
Import-Module Adaxes

$containerDN = "CN=Computers,DC=domain,DC=com"

$computers = Get-AdmComputer -Filter * -SearchBase $containerDN  `
    -SearchScope OneLevel -Server "domain.com" -AdaxesService localhost 

foreach ($computer in $computers)
{
    Write-Host $computer.Name
}

See also