[英]Why is my REST output being trimmed with an ellipses in PowerShell?
I am using Invoke-RestMethod
to manage a Websense server. 我正在使用
Invoke-RestMethod
来管理Websense服务器。 When I use the following curl
command to list categories from a terminal my results are as expected: 当我使用以下
curl
命令从终端列出类别时,我的结果与预期的一样:
curl -k -u <username>:<password> -X GET https://<ipaddress>:<port>/api/web/v1/categories/all
The output I receive is: 我收到的输出是:
I am trying to take this content and save it into a variable so I can output it to a file (preferably a CSV). 我正在尝试将这些内容保存到变量中,以便将其输出到文件(最好是CSV)中。 When I attempt to run the command as a variable or when I output the content to a text file my response is trimmed for some reason with an ellipses at the end of the text string.
当我尝试将命令作为变量运行或将内容输出到文本文件时,由于某种原因,我的响应会因文本字符串末尾的省略号而被剪裁。 How do I get the content to output to the file the same as it appears on screen?
如何将内容输出到与屏幕上显示的内容相同的文件? Using
fl
gives slightly more data and using ft -auto
has no effect at all. 使用
fl
提供更多数据,而使用ft -auto
则完全没有效果。
Invoke-RestMethod -Uri $uriListCat -Method Get -Headers $headers |
Out-File u:\debug.txt
Categories ---------- {@{Category Description=Sites that provide access to business-oriented web applications and allow storage of sensitive data, excluding those for web collaboration.; Category Hier...
Invoke-RestMethod
returns the result as a PowerShell object data structure. Invoke-RestMethod
将结果作为PowerShell对象数据结构返回。 Convert it to JSON before writing it to a file if you want the output in JSON format: 如果要以JSON格式输出,请先将其转换为JSON,然后再写入文件:
Invoke-RestMethod ... |
ConvertTo-Json -Depth 10 |
Out-File ...
If you want the result as a CSV expand the Categories
property and export the resulting list as a CSV: 如果您希望将结果作为CSV格式,请展开
Categories
属性并将结果列表导出为CSV:
Invoke-RestMethod ... |
Select-Object -Expand Categories |
Export-Csv 'C:\categories.csv' -NoType
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.