![]() |
|
|
#1 |
|
Guest
Posts: n/a
|
Finding Exchange 2003 Servers in AD
I have a script which queries AD and lists all Exchange 2003 servers.
$root= New-Object System.DirectoryServices.DirectoryEntry("LDAP://RootDSE") $cfgNC = [adsi]("LDAP://" + $root.Get("configurationNamingContext")) $search = New-Object System.DirectoryServices.DirectorySearcher($cfgNC) $search.filter = '(objectclass=msExchExchangeServer)' $ExchServer = $search.FindAll() You get the results in the format: LDAP://CN=EXCH1,CN=Servers,CN=First Administrative Group,C........ I need to get them listed as: EXCH1 EXCH2 etc.... So far I can get to CN=EXCH1 CN=EXCH2 with $t = @() foreach ($server in $ExchServer) { $s = ([string]$server.properties.distinguishedname).split(",") $t = $t + $s[0] } but I can't get on from there to what I need and I don't think its a particulalry good way to have done it anyway. So can anyone help me get to where I need? Thanks |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: Finding Exchange 2003 Servers in AD
$ExchServer | foreach {$_.properties.name} --- Shay Levi $cript Fanatic http://scriptolog.blogspot.com > I have a script which queries AD and lists all Exchange 2003 servers. > > $root= New-Object > System.DirectoryServices.DirectoryEntry("LDAP://RootDSE") > $cfgNC = [adsi]("LDAP://" + $root.Get("configurationNamingContext")) > $search = New-Object > System.DirectoryServices.DirectorySearcher($cfgNC) > $search.filter = '(objectclass=msExchExchangeServer)' > $ExchServer = $search.FindAll() > You get the results in the format: > > LDAP://CN=EXCH1,CN=Servers,CN=First Administrative Group,C........ > > I need to get them listed as: > > EXCH1 > EXCH2 > etc.... > So far I can get to > > CN=EXCH1 > CN=EXCH2 > with > > $t = @() > > foreach ($server in $ExchServer) > { > $s = ([string]$server.properties.distinguishedname).split(",") > $t = $t + $s[0] > } > but I can't get on from there to what I need and I don't think its a > particulalry good way to have done it anyway. > > So can anyone help me get to where I need? > > Thanks > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: Finding Exchange 2003 Servers in AD
Brilliant! Thanks indeed.
"Shay Levi" wrote: > > > $ExchServer | foreach {$_.properties.name} > > > --- > Shay Levi > $cript Fanatic > http://scriptolog.blogspot.com > > > I have a script which queries AD and lists all Exchange 2003 servers. > > > > $root= New-Object > > System.DirectoryServices.DirectoryEntry("LDAP://RootDSE") > > $cfgNC = [adsi]("LDAP://" + $root.Get("configurationNamingContext")) > > $search = New-Object > > System.DirectoryServices.DirectorySearcher($cfgNC) > > $search.filter = '(objectclass=msExchExchangeServer)' > > $ExchServer = $search.FindAll() > > You get the results in the format: > > > > LDAP://CN=EXCH1,CN=Servers,CN=First Administrative Group,C........ > > > > I need to get them listed as: > > > > EXCH1 > > EXCH2 > > etc.... > > So far I can get to > > > > CN=EXCH1 > > CN=EXCH2 > > with > > > > $t = @() > > > > foreach ($server in $ExchServer) > > { > > $s = ([string]$server.properties.distinguishedname).split(",") > > $t = $t + $s[0] > > } > > but I can't get on from there to what I need and I don't think its a > > particulalry good way to have done it anyway. > > > > So can anyone help me get to where I need? > > > > Thanks > > > > > |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|