将powershell脚本更改为不带省略号的输出(...)

时间:2022-06-17 21:42:54

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.

我需要一些关于以下脚本输出的帮助,因此输出不会显示省略号(...)。我试图插入“| Format-Table -Wrap -AutoSize”但我似乎并没有把它弄好。

 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.

谢谢你的阅读。

2 个解决方案

#1


13  

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

Format-List(fl)或Format-Table -auto(ft -auto)应该有帮助。

$services | fl

OR

要么

$services | ft -auto

#2


14  

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 (...).

快速故事:使用带有Powershell的Microsoft Online Services模块运行命令,大部分结果不断被检索为截断数据截止并丢失为省略号(...)。

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.

修复:正如Greig在这篇文章中所解释的那样,我不可避免地得出结论$ FormatEnumerationLimit = -1是该问题的不可思议的解决方案。使用Format-Wide,Format-List,Format-Table,Format-Custom,-AutoSize,Out-String -Width等的任何变体都需要大量额外的注意事项/代码。在你想要的只是看到所有返回的数据的情况下,无论列,数组等,$ FormatEnumerationLimit = -1确保你将获得所有东西,你不需要乱七八糟。

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

Greig的帖子中记载的其他信息包括:

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

PowerShell快速提示:使用PowerShell创建宽表,作者解释:

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.

如果您具有包含项集合的特定属性,则如果该集合中的项目数超过分配给内置$ FormatEnumerationLimit变量的数量,则该属性仍可能在此处生成的文件中显示省略号。

...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.

...并且“将结果传递给| Format-Table -Property * [将]显示所有列。”但是列中的内容可能仍会被截断(“PowerShell默认情况下会截断表输出”),甚至使用| Format-Table -Property * -AutoSize将受到屏幕缓冲区的限制(“自动调整大小的表格仅限于屏幕缓冲区的宽度”)。在绝对$ FormatEnumerationLimit = -1之前提供的解决方案似乎正在使用| Format-Table -Property * -AutoSize与|一起使用Out-String -Width 4096或您需要的任何宽度。

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

使用格式命令更改输出视图提供了有关格式cmdlet的更多详细文档:格式范围,格式列表和格式表。

#1


13  

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

Format-List(fl)或Format-Table -auto(ft -auto)应该有帮助。

$services | fl

OR

要么

$services | ft -auto

#2


14  

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 (...).

快速故事:使用带有Powershell的Microsoft Online Services模块运行命令,大部分结果不断被检索为截断数据截止并丢失为省略号(...)。

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.

修复:正如Greig在这篇文章中所解释的那样,我不可避免地得出结论$ FormatEnumerationLimit = -1是该问题的不可思议的解决方案。使用Format-Wide,Format-List,Format-Table,Format-Custom,-AutoSize,Out-String -Width等的任何变体都需要大量额外的注意事项/代码。在你想要的只是看到所有返回的数据的情况下,无论列,数组等,$ FormatEnumerationLimit = -1确保你将获得所有东西,你不需要乱七八糟。

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

Greig的帖子中记载的其他信息包括:

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

PowerShell快速提示:使用PowerShell创建宽表,作者解释:

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.

如果您具有包含项集合的特定属性,则如果该集合中的项目数超过分配给内置$ FormatEnumerationLimit变量的数量,则该属性仍可能在此处生成的文件中显示省略号。

...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.

...并且“将结果传递给| Format-Table -Property * [将]显示所有列。”但是列中的内容可能仍会被截断(“PowerShell默认情况下会截断表输出”),甚至使用| Format-Table -Property * -AutoSize将受到屏幕缓冲区的限制(“自动调整大小的表格仅限于屏幕缓冲区的宽度”)。在绝对$ FormatEnumerationLimit = -1之前提供的解决方案似乎正在使用| Format-Table -Property * -AutoSize与|一起使用Out-String -Width 4096或您需要的任何宽度。

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

使用格式命令更改输出视图提供了有关格式cmdlet的更多详细文档:格式范围,格式列表和格式表。