adsi management

Managing Directory Services

Our recommendation is that if you have VBScripts to manage Active Directory using ADSI, continue to use them.

If your directory service management needs are simple, say you want to be able to find users, you can actually use WMI and the Get-Wmiobject cmdlet to query Active Directory:

#GetLDAPUsers.ps1

$user=read-host "What user credentials do you want to use for" `
"authentication to the" `n `
"domain controller? Use format domain\username."
$cred=get-credential $user
$server=read-host "What domain controller do you want to connect to?"

$rc=read-host "Do you also want to save output to a text file? [YN]"
if ($rc -eq "Y") {
$file=read-host "Enter the filename and path"
write-host "Connecting to" $server "as" $user
get-wmiobject -class ds_user -namespace root\directory\ldap `
-computername $server -credential $cred | `
select-object DS_Name,DS_distinguishedname,DS_sAMAccountname |`
tee-object -file $file
}
else
{
write-host "Connecting to" $server "as" $user
get-wmiobject -class ds_user -namespace root\directory\ldap `
-computername $server -credential $cred | `
select-object DS_Name,DS_distinguishedname,DS_sAMAccountname
}