TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

Notices

Reply
 
Thread Tools Display Modes
Old 26-06-2008, 04:29 PM   #1
jmedd
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
  Reply With Quote
Old 26-06-2008, 04:29 PM   #2
Shay Levi
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
>



  Reply With Quote
Old 26-06-2008, 04:30 PM   #3
jmedd
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
> >

>
>
>

  Reply With Quote
Reply

Thread Tools
Display Modes


Google
 


All times are GMT +5.5. The time now is 03:00 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional