如何显示System.Object [] Powershell,invoke-webrequest [英] How can I show inside of System.Object[] Powershell, invoke-webrequest

查看:280
本文介绍了如何显示System.Object [] Powershell,invoke-webrequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下

       $username = "username"
        $password = "password"

        $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

        $response = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://api.bitbucket.org/2.0/teams/Ateam/members -Method Get

$new = $response |select Values 

$new

$new|Export-Csv C:\Users\helloworld\Desktop\BitBucket\Ateam.team.csv -NoTypeInformation  

我可以在Powershell Board上看到Values的内部。

when I execute this script, I can see the inside of "Values" like this on my Powershell Board.

values                                                                                                                                                                                                                             
------                                                                                                                                                                                                                             
{@{username=helloworld; website=; display_name=rhelloworld; uuid ={dewi3urgfj-.

但我检查了我的csv,它说这样

but I checked my csv, it says like this

values
System.Object[]

我想在这样的csv上显示,

I would like to show on my csv like this also,

 {@{username=helloworld; website=; display_name=rhelloworld; uuid ={dewi3urgfj-.

如何在csv上显示System Object []新?

How can I show inside of "System Object[]" on my csv like when I execute "$new"?

推荐答案

你的对象$ new中有一个额外的属性'values'。现在,它正在将values导出为列,然后将对象列表作为单元格。

You have an additional property 'values' in your object $new. At the moment it is exporting 'values' as a column an then the list of objects as a cell.

您可以将单元格转换为JSON,如下所示:

You could convert your cell to JSON like this:

$new.values  = $new.values | ConvertTo-Json -Compress

但是我个人不知道为什么要导出为CSV喜欢这个。它很难读取,CSV只有一列和一行。

But personally I don't see why you would want to export to a CSV like this. It is hardly readable and CSV has just one column and one line.

您确定不要只是将对象列表导出为CSV,如下所示:

Are you sure you don't just want to export the list of objects to a CSV like this:

$new.values | Export-Csv C:\Users\helloworld\Desktop\BitBucket\Ateam.team.csv -NoTypeInformation

这篇关于如何显示System.Object [] Powershell,invoke-webrequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆