If im in exchange shell, and i want to get a list of all the cas servers in the arrray I would tyep get-clientaccessarray | and grab the members of it. In turn I would get something like:
server1.company.com,server2.company.com.
So is there a way to get the list of all the server in the array by doing a LDAP call to AD? I would like to make the call to ad and see it it runs any quicker.
Any thoughts??
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()$root = $dom.GetDirectoryEntry()$array = @("server1", "server2", "server3")$root = New-Object System.DirectoryServices.DirectoryEntry(LDAP://dc=contoso,dc=com)$searcher = New-Object System.DirectoryServices.DirectorySearcher$searcher.SearchRoot = $root$searcher.PageSize = 1000$searcher.SearchScope = "Subtree" foreach($server in $array){ $searcher.Filter = "(CN=$server)" $result = $searcher.Findone() $path = [ADSI]$result.path $path}
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()$root = $dom.GetDirectoryEntry()$array = @("server1", "server2", "server3")$root = New-Object System.DirectoryServices.DirectoryEntry(LDAP://dc=contoso,dc=com)$searcher = New-Object System.DirectoryServices.DirectorySearcher$searcher.SearchRoot = $root$searcher.PageSize = 1000$searcher.SearchScope = "Subtree"
foreach($server in $array){
$searcher.Filter = "(CN=$server)" $result = $searcher.Findone() $path = [ADSI]$result.path $path}
OK if I run the $root = $dom.GetDirectoryEntry(), part I get:
distinguishedname: {Dc=,Dc=,Dc=}
path: LDAP://...
SO how to I populate :
$root = New-Object System.DirectoryServices.DirectoryEntry(LDAP://dc=contoso,dc=com), with the domain im In?
This is where im getting hung up? THx.
Sorry I think I was sleepy when I wrote that...
Try that instead:
$array = @("server1", "server2", "server3")$root = New-Object System.DirectoryServices.DirectoryEntry("LDAP://dc=contoso,dc=com")$searcher = New-Object System.DirectoryServices.DirectorySearcher$searcher.SearchRoot = $root$searcher.PageSize = 1000$searcher.SearchScope = "Subtree"foreach($server in $array){$searcher.Filter = "(CN=$server)"$result = $searcher.Findone()$path = [ADSI]$result.path$path}
The problem is that you need to know the server names to find them in AD - this is self defeating. The cmdlets search for you. I don't think you'll find a manual search is any more efficient and depends on you knowing the result before you start!