-1

我需要使用“hostIDs”和“Fields”数据生成令牌。如果我只使用“hostID”它可以工作,但该令牌无效。

下面是适用于 Postman 但不适用于 PowerShell 的 JSON 正文代码。

{   
"hostIds":[8876767,6736742,0986374],    
"fields": ["ServiceTag","HardwareManufacturer","HardwareModel"]
}

JSON 正文下方仅适用于带有“hostID”的 Powershell。我还想在此主体“字段”中添加另一行,以完成令牌生成。如何添加多行?

$body = ConvertTo-Json @{   
          hostIds = 8876767,6736742,0986374
          
}

我用于此 API 的 PowerShell 代码:-

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

#JSON Body
$body = ConvertTo-Json @{   
          hostIds = 8876767, 6736742,0986374             
}

$EndPointURI = 'https://secure.logmein.com/public-api/v1/inventory/system/reports'

$response = Invoke-RestMethod -Uri $EndPointURI -Method Post -Headers @{Authorization=("Basic {0}" -f $headers)} -Body $body -ContentType 'application/json'
$token = $response.token
4

1 回答 1

0

语法是这样的:

$body = ConvertTo-Json @{   
    hostIds = @('8876767', '6736742', '0986374')
    fields = @('ServiceTag', 'HardwareManufacturer', 'HardwareModel')
}

或者像这样:

$body = ConvertTo-Json @{   
    hostIds = @('8876767', '6736742', '0986374');
    fields = @('ServiceTag', 'HardwareManufacturer', 'HardwareModel');
}
于 2020-06-25T09:55:25.380 回答