37

I need some help with the output of the following script so the output doesn't show with the ellipses (...). I tried to insert | Format-Table -Wrap -AutoSize but I just can't seem to get it right.

 clear-host Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue    
 $services = new-object system.collections.sortedlist
 $servers = (get-spfarm).servers  
 foreach ($server in $servers) {
     foreach($service in $server.serviceinstances)
     {
         if ($service.status = "Online")
         {
             $s = $service.typename
             if ($services.contains($s))
             {
                 $serverlist = $services[$s]
                 $servername = $server.name 
                 $services[$s]  = "$serverlist - $servername"
             }
             else
             {
                 $services[$s] = $server.name
             }
         }
     } } 
  $services

output:

Name                            Value                                                                           
----                           -----                                                                           
Access Database Service        SE5APP - SE5FE - SE7FE - FAQ3                                          
Application Discovery **and L...** SE5APP - SE5FE - SE7FE - FAQ3                                          
Application Registry Service   SE5APP - SE5FE - SE7FE - FAQ3                                          
1
  • Can you show an example of the output with the ellipses?
    – David
    Dec 6, 2012 at 1:58

3 Answers 3

41

Either Format-List (fl) or Format-Table -auto (ft -auto) should help here.

$services | fl

OR

$services | ft -auto
3
  • 4
    Ended up using | Format-Table -Wrap -AutoSize, but it was because of you that i understood where to actually insert the code. Thanks.
    – MicroSumol
    Dec 6, 2012 at 4:04
  • What if I want to show a truncated error in the output that contains + category info? I get ResourceExists: (CN=tk,OU=Schwab.... The 3 dots are nasty..
    – Timo
    Jan 30, 2020 at 6:57
  • So you must know beforehand if your result will be a list or a table.**Get-service** returns a list and so fl works, but it looks like a table.
    – Timo
    Dec 16, 2020 at 18:06
26

I came across this post and would like to add some information, as the accepted solution did not resolve my problem and I'm sure others may find the following information useful:

Quick Story: Running commands using Microsoft Online Services Module with Powershell, much of the results were continually be retrieved as truncated with data cutoff and missing as an ellipsis (...).

The fix: As explained in this post by Greig, I inevitably came to the conclusion $FormatEnumerationLimit=-1 is the unlimate solution to the problem. Using any variant of Format-Wide, Format-List, Format-Table, Format-Custom, -AutoSize, Out-String -Width, etc. require a hefty amount of additional considerations/code. In the case where all you want is to see all the data being returned, regardless of columns, arrays, etc., $FormatEnumerationLimit=-1 ensures you will get everything and you don't need to mess around.

Additional information, as credited in Greig's post include:

PowerShell Quick Tip: Creating wide tables with PowerShell, where the author explains:

If you have a specific property that contains a collection of items, that property may still show an ellipsis in the file produced here if the number of items in that collection exceeds the number assigned to the built-in $FormatEnumerationLimit variable.

...and that "passing the results to | Format-Table -Property * [will] show all of the columns." But content from the columns may still be truncated ("PowerShell truncates table output by default"), and that even using | Format-Table -Property * -AutoSize will be limited by your screen buffer ("Auto-sized tables are limited to the width of your screen buffer"). The solution offered, before the absolute $FormatEnumerationLimit=-1, seems to be using | Format-Table -Property * -AutoSize in conjunction with | Out-String -Width 4096 or whatever width you require.

Using Format Commands to Change Output View provides some more delailed documentation on the Format cmdlets: Format-Wide, Format-List, and Format-Table.

3
  • 3
    | Format-Table -Property * -AutoSize | Out-String -Width 4096 worked for me.
    – GuruKay
    Sep 21, 2017 at 8:43
  • @TryTryAgain The "Using Format Commands to Change Output View" link in your post is broken. Here is a working link. Jan 12, 2018 at 14:59
  • @MassDotNet thanks for pointing that out. Old one, looks like that is not longer available so I've changed the link to point to the way back machine. Jan 12, 2018 at 20:23
0

What I do in this situation is to create a format description then use that as an argument to my Format-Table command. I've developed a function (Get-MaxLength) to examine the data field with the longest data (helps to have this at the end of the format description) and set the width in the format description with the value it returns. You can see the calculations in the code below. Notice the Number value for the Intel(4) Management Engine Interface. Also notice the use of -Wrap on the Format-Table command. This concept can be modified to calculate all fields widths or just the last one, it's just a little math.

Function Get-MaxLength {

<#
.SYNOPSIS
   Finds the length of the longest item in collection.

.DESCRIPTION
   Use this Function to get the length of the longest item in a
   collection for use in format strings or other places where
   needed.

.PARAMETER TestObj
    The qualified object to be tested. See example!

.Parameter MinLen
    The minimum length of the item (if using for formatting) which
    should be the Label (title) length. Note if the object item
    being tested does not have a Length property you MUST specify
    the label length!

.OUTPUTS
    Returns a numerical value

.EXAMPLE
   $NameLen = Get-MaxLength -TestObj $DotNet.PSChildName
   $VerLen  = Get-MaxLength -TestObj $DotNet.Version
   $RNLen   = Get-MaxLength -TestObj $DotNet.Release -MinLen 11

     #--- .Net Information ---

 $fmtDotNet =
  @{Expression={$_.PSChildName};Label=".Net Type";Width=$NameLen},
  @{Expression={$_.Version};Label="Version No:";Width=$VerLen},
  @{Expression={$_.Release};Label="Release No:";Width=$RNLen}

  $Dotnet | Format-Table $fmtDotNet
#>

  Param(
    [Parameter(Mandatory=$True)]
     [object] $TestObj,
    [Parameter(Mandatory=$False)]
     [int] $MinLen = 0,
    [Parameter(Mandatory=$False)]
     [int] $MaxLen = 0
  )

   $ErrorActionPreference = "SilentlyContinue"

   foreach ($x in $TestObj) {
     If ($x.Trim().length -gt $MinLen) {
       $MinLen = $x.Trim().length
     }
   }

   If ($MaxLen -ne 0) {
     If ($MinLen -gt $MaxLen) {
       $MinLen = $MaxLen
     }
   }

   $ErrorActionPreference = "Continue"

   Return ,$MinLen

} #End Function -----------  Get-MaxLength  -------------------

  $OstrWidth = 80
  
  $DriverInfo =
  Get-CimInstance -ClassName 'Win32_PNPSignedDriver'         |
  Where-Object -Property DriverProviderName  -ne "Microsoft" |
  Where-Object -Property DeviceName -ne -Value $Null         |
  Sort-Object  -Property DeviceName -Unique

$DriverCnt = $DriverInfo.Count

  $DVLen =
    Get-MaxLength -TestObj $DriverInfo.DriverVersion -MinLen 14
  $DDLen = $OstrWidth - $DVLen

  $fmtDRVR = @{Label="`nDriver Description";Width=$DDLen;
                                 Expression={$_.DeviceName}},
             @{Label="Version Number";    Width=$DVLen;
                                 Expression={$_.DriverVersion}}

  $DrvTitle = "$($DriverCnt) Non-Windows Unique Drivers and " +
              "Version Numbers:" | Out-String

  $DriverInfo =
    $DriverInfo | Format-Table -Property $fmtDRVR -Wrap |
                  Out-String   -Width $OStrWidth

Sample Output:

Driver Description                                                 Number
-------------------                                                -------------
Alcor Micro USB 2.0 Card Reader                                    2.0.150.10135
ASMedia USB3.1 eXtensible Host Controller                          1.16.42.1
...
Intel(R) HD Graphics 630                                           21.20.16.4550
Intel(R) Management Engine Interface                               1914.12.0.125
                                                                   6
Intel(R) Ready Mode Technology Device                              1.2.0.0
...
Realtek Audio                                                      6.0.1.8248
Samsung NVMe Controller                                            3.0.0.1802

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.