Solved

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

Posted on 2014-12-02
12
591 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
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.

 

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

Is Your AD Toolbox Looking More Like a Toybox?

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.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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