[英]Reading powershell objects returned by Invoke-RestMethod
I am having trouble using Invoke-RestMethod
in PS and retrieving the results... 我在PS中使用
Invoke-RestMethod
并检索结果时遇到问题...
here is my code: 这是我的代码:
$request='https://sandbox.api.dell.com/support/assetinfo/v4/getassetwarranty/SERVICETAG?apikey=APIKEY'
Invoke-RestMethod $request |
Select $request.ServiceTag
The JSON returned by the DELL API call looks like this: DELL API调用返回的JSON如下所示:
{
"AssetWarrantyResponse": [
{
"AssetHeaderData": {
"BUID": "202",
"ServiceTag": "XXXXXXX",
"ShipDate": "2017-12-04T18:00:00",
"CountryLookupCode": "UK",
"LocalChannel": "ENTP",
"CustomerNumber": "NNNNNN",
"ItemClassCode": "OB002",
"IsDuplicate": false,
"MachineDescription": "Latitude 7480",
"OrderNumber": "123456789",
"ParentServiceTag": null
},
"ProductHeaderData": {
"SystemDescription": "Latitude 7480",
"ProductId": "latitude-14-7480-laptop",
"ProductFamily": "Laptops",
"LOB": "Latitude",
"LOBFriendlyName": "Latitude"
},
"AssetEntitlementData": [
{
"StartDate": "2017-12-04T18:00:00",
"EndDate": "2020-12-05T17:59:59",
"ServiceLevelDescription": "Onsite Service After Remote Diagnosis (Consumer Customer)/ Next Business Day Onsite After Remote Diagnosis (Commercial Customer)",
"ServiceLevelCode": "ND",
"ServiceLevelGroup": 5,
"EntitlementType": "INITIAL",
"ServiceProvider": null,
"ItemNumber": "123-12345"
},
{
"StartDate": "2017-12-04T06:00:00",
"EndDate": "2025-12-05T05:59:59",
"ServiceLevelDescription": "Dell Digitial Delivery",
"ServiceLevelCode": "D",
"ServiceLevelGroup": 11,
"EntitlementType": "INITIAL",
"ServiceProvider": null,
"ItemNumber": "525-10302"
}
]
}
],
"InvalidFormatAssets": { "BadAssets": [ ] },
"InvalidBILAssets": { "BadAssets": [ ] },
"ExcessTags": { "BadAssets": [ ] },
"AdditionalInformation": null
}
I need to get several values from that JSON response, I tried using ConvertFrom-Json
with |Select ServiceTag, SystemDescription, EndDate
by following the advice in MS TechNet Scripting Guy: Playing with JSON and PowerShell 我需要从该JSON响应中获取多个值,我尝试按照MS TechNet脚本专家的建议使用
ConvertFrom-Json
和|Select ServiceTag, SystemDescription, EndDate
进行操作:使用JSON和PowerShell
But couldn't get values for ServiceTag, SystemDescription, EndDate (they were blank) - eventually we need to run this in a script for nearly 1500 computers in blocks of 80 at a time and update a database 但是无法获取ServiceTag,SystemDescription和EndDate的值(它们为空)-最终,我们需要在脚本中针对近1500台计算机以80个块的形式一次运行它,并更新数据库
So where am I going wrong here? 那我在哪里错了?
I did try something like Invoke-RestMethod $request | Select $request.AssetHeaderData.ServiceTag
我确实尝试过类似
Invoke-RestMethod $request | Select $request.AssetHeaderData.ServiceTag
Invoke-RestMethod $request | Select $request.AssetHeaderData.ServiceTag
but had no luck Invoke-RestMethod $request | Select $request.AssetHeaderData.ServiceTag
但没有运气
$req = Invoke-RestMethod $request
$warranties = $req.AssetWarrantyResponse.AssetEntitlementData[0]
$dellasset = $req.AssetWarrantyResponse.productheaderdata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.