Solved

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

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

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now