Active Directory: Does Specified User Exist?
This code has been in my drafts box for 2 years. I figured I'd just go ahead and publish it, though I'm unsure of the context now.
1$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
2$root = $dom.GetDirectoryEntry()
3$search = [System.DirectoryServices.DirectorySearcher]$root
4$search.Filter = "(objectcategory=domainDNS)"
5$result = $search.FindOne()
6$domain = $result.GetDirectoryEntry()
7$domain |fl *
8
9if ($result) {
10 $user = $result.GetDirectoryEntry()
11 Write-Host $user.name " exists"
12} else {
13 Write-Host $struser " Does not exist"
14}