List group members from different Domain with directory searcher
hi, trying users belong specific group in different domain cmdlet get-adgroupmember has bug , can't see them..
so thinking of using directoy searcher alternative creds not sure how proceed..
the original script goes as:
$username= "domain\user"
$passwd= "password"
$securepassword = convertto-securestring $passwd -asplaintext -force
$creds= new-object system.management.automation.pscredential $username, $securepassword
$domain = "contoso.com"
$admin= get-adgroupmember "administrators" -server $domain-credential $creds
with directorysearcher have tried...
$dn = new-object system.directoryservices.directoryentry ("ldap://contoso.com:389/","domain\username","password")# here user
$search= new-object system.directoryservices.directorysearcher($dn)
$search.filter = "(&(objectcategory=group)(name=administrators))"
$search.searchscope = "subtree"
$search.propertiestoload.add("samaccountname");
$list = $search.findall()
but can't work, ideas?
thanks
if get-adgroupmember won't work adsi not work.
you doesn't work fail means.
with adsi need specify secure connection.
$dn = new-object system.directoryservices.directoryentry ('ldap://testnet.local', 'testnet\admin', 'pass@word#','secure') $search = new-object system.directoryservices.directorysearcher($dn,'(&(objectcategory=group)(name=administrators))') $group=$search.findone() $group.properties['member']
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment