Skip to content

Enumerating computer accounts

The following code sample enumerates computer accounts located in a specific Organizational Unit.

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

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

# Bind to the Organizational Unit
$containerDN = "CN=Computers,DC=domain,DC=com"
$container = $admService.OpenObject("Adaxes://$containerDN", $NULL, $NULL, 0)

$container.Filter = @("computer")

foreach ($computer in $container)
{
    Write-Host $computer.Get("name")
}
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