$access_token ="secret"
$URI = "https://oui.web.ser.ons"
$headers = @{“authorization” = “Bearer $access_token”}
$result = Invoke-RestMethod -Uri $URI -Headers $headers -ContentType $ContentType |ConvertTo-Json
$b = $Result|ConvertFrom-Json| Select -ExpandProperty audits
$Dates = $b | Foreach-Object {$_.modified_at = [DateTime]$_.modified_at; $_} |
Group-Object Computer |
Foreach-Object {$_.Group | Sort-Object $_.modified_at | Select-Object -Last 2}
$Audit_id = $Dates| Select audit_id | ft -hidetableheaders
$Audit_id= a_6d62b1f4d66c4a1a83c244469af93d3d
a_0bf1e6b1a1c243539a9dbb241e920d0a
使用下面的脚本在下面出现错误:我试图循环$ Audit_id并获取JSON文件。
$Audit_id= a_6d62b1f4d66c4a1a83c244469af93d3d
a_0bf1e6b1a1c243539a9dbb241e920d0a
$uri = 'https://oui.web.ser'
$reportList = @(
$Audit_id
)
$token = 'secret'
$headers = @{ Headers = @{ Authorization = "Bearer $token" }}
foreach ($report in $reportList) {
Invoke-RestMethod -Uri "$uri/$report" @headers |ConvertTo-Json
但是我收到下面的错误。似乎不喜欢包含“ /”的-Uri“ $ uri / $ report” @headers行。