[英]Powershell Invoke-WebRequest XML data
I have a major API request I´m trying to do with Powershell to send further on as JSON to PowerBI.我有一个主要的 API 请求我正在尝试处理 Powershell 以进一步发送 JSON 到 Z92B93BFB91D5BCAZAD1。 The XML format is as followed (but much larger):
XML 格式如下(但更大):
<queryResponse last="99" first="0" count="2" type="APD" responseType="list" requestUrl="an URL" rootUrl="root URL">
<entity dtoType="aPDDTO" type="APD" url="URL_ID">
<accessPointDetailsDTO displayName="ID" id="ID">
<adminStatus>ENABLE</adminStatus>
<apType>AP2600I</apType>
<clientCount_5GHz>2</clientCount_5GHz>
<status>CLEARED</status>
<type>UnifiedAp</type>
<cdpNeighbors>
<cdpNeighbor>
<capabilities>Switch IGMP </capabilities>
<duplex>Full Duplex</duplex>
<interfaceSpeed>100Mbps</interfaceSpeed>
I would like to be able to send not all but specified fields furter on.我希望能够进一步发送除指定字段之外的所有字段。 I have a loop used before when a API used JSON which I tried to use:
当 API 使用我尝试使用的 JSON 时,我之前使用了一个循环:
while ($true) {
$AccessPointDetails = Invoke-WebRequest -Uri $Uri -Headers @{"Authorization"="Basic $BasicCreds"}
foreach ($AccessPoint in $AccessPointDetails) {
$payload = @{
"adminStatus" = $AccessPoint.adminStatus
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
sleep 100
}
}
I don´t get any values so I guess It doesn´t know where the data is.我没有得到任何值,所以我猜它不知道数据在哪里。
EDIT 1编辑 1
I found some hint about doing like below to present the data at the end of my code:我发现了一些关于在代码末尾显示数据的提示:
[ xml ]$fileContents = Get-Content -Path $Result
The problem is it seems to dislike my first row in the data I'm trying to read from since it cast this error to me:问题是它似乎不喜欢我试图读取的数据中的第一行,因为它向我抛出了这个错误:
Get-Content : Cannot find drive. A drive with the name '<?xml version="1.0" ?>
I Usually get the json content, write it into a simple txt file, add the rows or values i need and then convert it into Json.我通常获取 json 内容,将其写入一个简单的 txt 文件,添加我需要的行或值,然后将其转换为 Json。
This usually let me to avoid any kind of issue这通常让我避免任何类型的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.