adsites powershell output question

Althought the below script gives me the output i have more servers in that site i can't see the whole server list how i can't  wrap the whole servers result 

Site       Servers                                                                                                                                                  
----       -------                                                                                                                                                  
CO1        {DBLPADDS002.innerspace.net, DBLPADS002.innerspace.net, DBLPADS001.innerspace.net, DBLPADDS001.innerspace.net...}

[array] $ADSites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites 

foreach ($adsite in $adsites){

 if ($adsite.name  -ne $null) {

    try {
     [pscustomobject]@{
        Site = $adsite.name;
        Servers = $adsite.servers}
        }
    catch{
        Write-Host "$_"
            }
       } 
}

    
January 30th, 2015 12:32am

Instead of:

Servers = $adsite.servers

You can do:

Servers = $adsite.servers -join ","

This will create a comma delimited string instead of the truncated array. When outputting to host, however, PowerShell will still automatically truncate a string. To get the full output, you may need to collect all those objects into an array and then write them to a file using Export-Csv.

  • Marked as answer by Ajit663 Thursday, January 29, 2015 11:02 PM
Free Windows Admin Tool Kit Click here and download it now
January 30th, 2015 1:18am

Use the pipeline.  It fixes alll of those things automatically.

[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites |
    Select Name, @{N='Servers';E={$_.Servers -join ';'}} |
    Format-Table -Wrap -AutoSize
January 30th, 2015 1:39am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics