Solved

how can i display the values that Get-ADDomainController asnwers in a foreach ?

Posted on 2014-12-02
12
569 Views
Last Modified: 2014-12-02
Hello experts,

i'm trying to get values out of the response of Get-ADDomainController but i dont succeed inside a foreach.

what am I doing wrong, i only receive three times the domain but no ip nor name.

here's what i wrote so far.

foreach($server in (Get-ADForest).globalcatalogs){
    foreach-object { 'server : {0, 20}  ---  IP : {0, 20}  ---  Name: {0, 20}' -f
     $(Get-ADDomainController -Server $server).Domain ,
     $(Get-ADDomainController -Server $server).IPv4Address,
     $(Get-ADDomainController -Server $server).Name
    }
}

thank you in advance.

toshi.
0
Comment
Question by:toshi_
  • 7
  • 5
12 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 40476407
Try this - only executes get-addomaincontroller once, instead of thrice:
foreach($server in (Get-ADForest).globalcatalogs){
  get-addomaincontroller -server $server | select domain, ipv4address, name
}

Open in new window

0
 

Author Comment

by:toshi_
ID: 40476415
;)

i'm begining with powershell, i'll keep your solution in mind ;)

thanks a lot.
0
 

Author Comment

by:toshi_
ID: 40476417
what about string controlling as i was trying to do ?
i'd like to have the responses more close one to each other.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:toshi_
ID: 40476424
i'm trying to display with string format  but i dont knwo where to it ?


i'm having error with the following line

foreach($server in (Get-ADForest).globalcatalogs){
  get-addomaincontroller -server $server | select '{0. 20}, -- {1, 20}, {2, 20} ' -f  domain, ipv4address, name
}
0
 

Author Comment

by:toshi_
ID: 40476430
not in such way either....



foreach($server in (Get-ADForest).globalcatalogs){
  get-addomaincontroller -server $server | select   domain, ipv4address, name | '{0. 20}, -- {1, 20}, {2, 20}' -f  domain, ipv4address, name
}
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40476432
This should accomplish that adjustment...

foreach($server in (Get-ADForest).globalcatalogs){
  get-addomaincontroller -server $server | format-table domain, ipv4address, name -autosize
}

Open in new window

0
 

Author Comment

by:toshi_
ID: 40476442
thank again, but autosize is not creating columns with the results...
can you help me with formating the result ?

how to get the result and play with {0,20} ?

toshi
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40476444
Oh, I see...
So, try this instead of your original script:
foreach($server in (Get-ADForest).globalcatalogs){
  $dc = get-addomaincontroller -server $server 
  'server : {0, 20}  ---  IP : {0, 20}  ---  Name: {0, 20}' -f $dc.domain, $dc.ipv4address, $dc.name
}

Open in new window

0
 

Author Comment

by:toshi_
ID: 40476455
thank for your quick reply,

this display is the same that i started with .....only the domain name is display three times .
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 40476459
Oh, ah...I overlooked that... increment the elements:
 'server : {0, 20}  ---  IP : {1, 20}  ---  Name: {2, 20}' -f $dc.domain, $dc.ipv4address, $dc.name
0
 

Author Comment

by:toshi_
ID: 40476464
youuuuuu rooock !

thanks a lot !
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40476487
Glad I could help. :^)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question