Reputation: 77
$ADResult = ([adsisearcher]"(samaccountname=$sams)").Findone()
I am using this statement to search in the AD the accounts with the samaccountnames as $sams, but the problem is that Im calling this from a different server and not from the one where AD's exist.
So, what I need to know is can I provide it details of the following -
and if yes, HOW?
Upvotes: 1
Views: 10122
Reputation: 8889
Set variables for your Domain Controller, Domain, Suffix and OU like this:
$DC = "DCServer"
$Domain = "MyDomain"
$Sufix = "Local"
$OU = "MyOU"
$SAMName = "SamAccountName"
Link your Searcher object to that info...
$Root = [adsi] "LDAP://$DC/OU=$OU,DC=$Domain,DC=$Suffix"
$Searcher = new-object System.DirectoryServices.DirectorySearcher($root)
$Searcher.filter = "(&(objectClass=user)(sAMAccountName= $SAMName))"
$Searcher.FindOne()
If you have Sub-OU's Add OU="OU1",OU="OU2" etc.
Upvotes: 4