header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Query Global Catalog
Last Post 12 Mar 2008 03:55 PM by tHyEstes. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
tHyEstesUser is Offline
New Member
New Member
Posts:13

--
11 Mar 2008 08:16 PM  

Hi All,

 
I found this script on the internet but this one searches a domain controller for a user.
I want search my global catalog for a user. I found the some information at msdn but
I am not that experienced in programming so I do not know how to translate it to
powershell. I guess the first couple of line need to be adjusted. Can somebody help me out?
 
 
Regards
Martijn
 
$struser = "BOSCH Herbert"

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()

$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(cn=$struser)"
$result = $search.FindOne()

if ($result -ne $null)
{
$user = $result.GetDirectoryEntry()
Write-Host $user.distinguishedName " exists"
}
else {Write-Host $struser " Does not exist"}

bsonposhUser is Offline
Basic Member
Basic Member
Posts:388

--
11 Mar 2008 08:27 PM  
Try this

$struser = "BOSCH Herbert"
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = [ADSI]"GC://$($dom.Name)"
$search = new-Object System.DirectoryServices.DirectorySearcher($root,"(cn=$struser)")
$result = $search.FindOne()

if ($result -ne $null){
$user = $result.GetDirectoryEntry()
Write-Host $user.distinguishedName " exists"
}
else
{
Write-Host $struser " Does not exist"
}
tHyEstesUser is Offline
New Member
New Member
Posts:13

--
12 Mar 2008 03:55 PM  
Hi Brandon,

Thanks for the fast reply. I tried it and it worked.

Regards,
Martijn
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer