使用PowerShell遍历API

时间:2019-03-01 04:51:22

标签: arrays json powershell

我正在使用以下API,并且需要从每个Org的数据列表中选择一些项(OrgName,MaxSeats和userCount)。以前的尝试已经接近完成,但是我什至无法将单个对象拉到userCount。

(Invoke-WebRequest -Credential $api_user 'https://console.us.code42.com/api/org?active=true&inccount=True&incsettings=True' -Method Get -UseBasicParsing |
    Select-Object Content |
    ConvertTo-Json).PSObject.Properties | ForEach-Object {
        Write-Host "$($_.name): $($_.value)"
    }

我正在调用的API与上面的URL相同;完整的描述可以在这里找到:https://console.us.code42.com/apidocviewer

添加来自Invoke-RestMethod的输出。

我确实从Invoke-RestMethod开始,到那里最接近了;但在其他地方看到Invoke-WebRequest是首选。仅标准调用的输出就在这里,OrgName和MaxSeats就在这里-但是我知道,如果我为每个ORG进行迭代,则userCount也可以通过API使用。

orgId                   : 2633
orgUid                  : xxxxxx
orgName                 : B Team
orgExtRef               : 
notes                   : 
status                  : Active
active                  : True
blocked                 : False
parentOrgId             : 1167
parentOrgUid            : xxxxxx
type                    : ENTERPRISE
classification          : BASIC
externalId              : xxxxxx
hierarchyCounts         : 
configInheritanceCounts : 
creationDate            : 2/10/19 11:45:48 PM
modificationDate        : 2/10/19 11:45:48 PM
deactivationDate        : 
registrationKey         : xxxxxxxx
reporting               : @{orgManagers=System.Object[]}
customConfig            : False
settings                : @{maxSeats=; maxBytes=}
settingsInherited       : @{maxSeats=; maxBytes=}
settingsSummary         : @{maxSeats=; maxBytes=}

如果您查看实际的API,它会列出许多其他项目,此处未见。我想这是个大问题。

我的API调用中的原始JSON输出-与文档页面的显示方式不同。

{
  "metadata": {
    "timestamp": "2019-03-01T12:50:36.296Z",
    "params": {
      "incsettings": "True",
      "active": "true",
      "inccount": "True"
    }
  },
  "data": {
    "totalCount": 4,
    "orgs": [
      "@{orgId=1172; orgUid=xxxx; orgName=A Team; orgExtRef=; notes=; status=Active; active=True; blocked=False; parentOrgId=1167; parentOrgUid=xxxx; type=ENTERPRISE; classification=BASIC; externalId=xxxx; hierarchyCounts=; configInheritanceCounts=; creationDate=04/22/2018 17:49:30; modificationDate=02/10/2019 23:44:27; deactivationDate=; registrationKey=xxxx; reporting=; customConfig=False; settings=; settingsInherited=; settingsSummary=}",
      "@{orgId=1173; orgUid=xxxx; orgName=Jurassic Park; orgExtRef=; notes=; status=Active; active=True; blocked=False; parentOrgId=1167; parentOrgUid=xxxx; type=ENTERPRISE; classification=BASIC; externalId=xxxx; hierarchyCounts=; configInheritanceCounts=; creationDate=04/22/2018 17:51:41; modificationDate=02/10/2019 23:26:07; deactivationDate=; registrationKey=xxxx; reporting=; customConfig=False; settings=; settingsInherited=; settingsSummary=}",
      "@{orgId=2633; orgUid=xxxx; orgName=B Team; orgExtRef=; notes=; status=Active; active=True; blocked=False; parentOrgId=1167; parentOrgUid=xxxx; type=ENTERPRISE; classification=BASIC; externalId=xxxx; hierarchyCounts=; configInheritanceCounts=; creationDate=02/10/2019 23:45:48; modificationDate=02/10/2019 23:45:48; deactivationDate=; registrationKey=xxxx; reporting=; customConfig=False; settings=; settingsInherited=; settingsSummary=}",
      "@{orgId=1167; orgUid=xxxx; orgName=Eric Hall SAAS SE Test - Backup; orgExtRef=; notes=; status=Active; active=True; blocked=False; parentOrgId=1121; parentOrgUid=xxxx; type=ENTERPRISE; classification=BASIC; externalId=xxxx; hierarchyCounts=; configInheritanceCounts=; creationDate=04/20/2018 21:10:03; modificationDate=02/10/2019 23:36:20; deactivationDate=; registrationKey=xxxx; reporting=; customConfig=False; settings=; settingsInherited=; settingsSummary=}"
    ]
  }
}

MAXSEATS字段显示在设置块中(尽管此处未显示)

0 个答案:

没有答案