首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell转换为不带标签的json

Powershell转换为不带标签的json
EN

Stack Overflow用户
提问于 2017-06-08 19:53:29
回答 0查看 1.2K关注 0票数 0

如何正确地将Powershell对象属性数组转换为json值数组,即在数组中不使用对象属性标签。

例如:我想为chart.js创建两个json数组,我将对一些进程对象进行分组:

代码语言:javascript
复制
$processgroup = get-process | group -property name

$processgroup.gettype()

IsPublic IsSerial Name                                     BaseType                                                                                 
-------- -------- ----                                     --------                                                                                 
True     True     Object[]                                 System.Array  

$chartlabels = $processgroup.name | convertto-json

$chartlabels

$chartlabels
[
    "ApMsgFwd",
    "ApntEx",
    "Apoint",
    "ApplicationFrameHost",
    "armsvc",
    "BtwRSupportService",
    "chrome",
    "com.docker.proxy",
    "com.docker.service",
    "concentr",
    "conhost",
    "csrss",
    "dllhost",
    "Docker for Windows",
    "dockerd",
    "dwm",
    "Everything",
    "EXCEL",
    "explorer",
    "fontdrvhost",
    "GROOVE",
    "hidfind",
    "HidMonitorSvc",
    "Idle",
    "iexplore",
    "IpOverUsbSvc",
    "jucheck",
    "jusched",
    "LicensingUI",
    "lsass",
    "mDNSResponder",
    "Memory Compression",
    "mqsvc",
    "MSASCuiL",
    "MsMpEng",
    "MSOIDSVC",
    "MSOIDSVCM",
    "MySQLNotifier",
    "NisSrv",
    "notepad",
    "notepad++",
    "nvSCPAPISvr",
    "nvvsvc",
    "nvwmi64",
    "nvxdsync",
    "OfficeClickToRun",
    "OneDrive",
    "OUTLOOK",
    "powershell",
    "powershell_ise",
    "prevhost",
    "Receiver",
    "redirector",
    "rundll32",
    "RuntimeBroker",
    "SearchIndexer",
    "SearchUI",
    "Secure System",
    "SecurityHealthService",
    "SelfServicePlugin",
    "services",
    "SettingSyncHost",
    "ShellExperienceHost",
    "sihost",
    "SkypeHost",
    "smss",
    "SMSvcHost",
    "spiceworks",
    "spiceworks-httpd",
    "spoolsv",
    "SppExtComObj",
    "sppsvc",
    "sqlwriter",
    "svchost",
    "System",
    "SystemSettings",
    "taskhostw",
    "TSVNCache",
    "vmcompute",
    "vmms",
    "vmnat",
    "vmnetdhcp",
    "vmware-authd",
    "vmware-tray",
    "vmware-usbarbitrator64",
    "wfcrun32",
    "wininit",
    "winlogon",
    "WINWORD",
    "WmiPrvSE",
    "WUDFHost"
]

#this is the array I want for charts labels, now for the chart value array

$chartvalues = $processgroup | select count | convertto-json

$chartvalues
[
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  30
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  5
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  4
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  30
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  75
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    },
    {
        "Count":  2
    },
    {
        "Count":  1
    },
    {
        "Count":  1
    }
]

如何省略"Count“标签,以便PowerShell只创建一个json数组,就像在进程名称数组中一样。

我试过了

代码语言:javascript
复制
$chartvalues = $processgroup.count

产生组数的计数结果

我试过了

代码语言:javascript
复制
$chartvalues = $ processgroup | select count -expandproperty count | convertto-json

结果与上面的示例相同

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44435067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档