Change powershell script to output without ellipses (…)

天涯浪子 提交于 2019-12-03 08:33:56

问题


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 don'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                                          

Thank you for reading.


回答1:


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

$services | fl

OR

$services | ft -auto



回答2:


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.



来源:https://stackoverflow.com/questions/13735275/change-powershell-script-to-output-without-ellipses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!