简体   繁体   English

为什么在PowerShell中用椭圆修剪我的REST输出?

[英]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.

相关问题 为什么此jQuery无法调用我的REST方法? - Why is my REST method not being called by this jQuery? 为什么不使用AngularJs因子从REST api中调用数据? - Why isn't data being called from my REST api using an AngularJs factor? 如何在powershell中输出从REST API返回的json对象? - How to output json object returned from REST api in powershell? 为什么REST端点被访问两次,第二次访问可以消除吗? - Why is the REST endpoint being accessed twice, and can the second access be eliminated? 为什么我的其余端点收到空的dto - Why my rest endpoint receives empty dto 为什么我的 API JSON 响应没有显示? - Why is my API JSON response not being displayed? 无法获取我的Rest Webservices的输出,并且正在获取HTTP 404异常 - Not able to get the output of my Rest Webservices and it is getting HTTP 404 exception 为什么我仅将JSON作为REST Web服务的输出? - Why do I get only JSON as output of the REST web service? 如何使用 Devops REST API 搜索带有 Powershell 的 Azure Devops 代码存储库并输出到 CSV - How to search Azure Devops Code Repos w/ Powershell using Devops REST API and output to CSV 为什么我的本地网站无法访问我的本地REST服务? - Why is my local website unable to access my local REST service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM