简体   繁体   English

Powershell Invoke-WebRequest XML 数据

[英]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.

相关问题 将 cURL 转换为 PowerShell Invoke-WebRequest - JSON 数据表问题 - Convert cURL to PowerShell Invoke-WebRequest - JSON data table issue 将简单的curl数据请求转换为Powershell invoke-webrequest - convert simple curl data request to powershell invoke-webrequest Powershell Invoke-WebRequest和字符编码 - Powershell Invoke-WebRequest and character encoding 使用PowerShell通过API查询Shopify JSON数据(Invoke-Webrequest错误401) - Querying Shopify JSON data via the API with PowerShell (Error 401 with Invoke-Webrequest) Powershell Invoke-Webrequest w/ JSON Body - 无法反序列化……? - Powershell Invoke-Webrequest w/ JSON Body - Can not deserialize…? 如何从 PowerShell 中的 Invoke-WebRequest 解析 JSON? - How to parse JSON from the Invoke-WebRequest in PowerShell? 如何解析/访问 Powershell 4 中 Invoke-WebRequest 返回的 JSON - How to parse/access JSON returned by Invoke-WebRequest in Powershell 4 Powershell:使用 Invoke-WebRequest,如何在 JSON 中使用变量? - Powershell: Using Invoke-WebRequest, How To Use Variable Within JSON? 如何为具有多个来自CSV变量的API调用设计“ Invoke-WebRequest”? (电源外壳) - How to design an “Invoke-WebRequest” for multiple API calls with more than one variable from CSV? (Powershell) 我如何显示在System.Object [] Powershell内部,invoke-webrequest - How can I show inside of System.Object[] Powershell, invoke-webrequest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM