参考`Invoke-RestMethod`的帮助文件:
PS /home/nicholas>
PS /home/nicholas> $response = Invoke-RestMethod -Uri https://blogs.msdn.microsoft.com/powershell/feed/
PS /home/nicholas>
PS /home/nicholas> $json = $response | ConvertTo-Json
WARNING: Resulting JSON is truncated as serialization has exceeded the set depth of 2.
PS /home/nicholas>
PS /home/nicholas> $xml = $response | ConvertTo-Xml
PS /home/nicholas>
PS /home/nicholas> $xml.OuterXml
我该如何将
response
转换为xml
并在一行中输出,就像上面的例子那样?
[xml]$testResult = (Invoke-RestMethod -Uri 'url').OuterXml
是不必要的 - 如果响应是 XML 文本,$testResult = Invoke-RestMethod -Uri 'url'
将会自动将其解析为[xml]
实例。我假设$testResult.Details.Status
只是演示如何深入了解[xml]
实例的一个例子,但建议您在回答中指出这一点。 - undefined