从 PowerShell 脚本调用 REST API [英] Call REST API from PowerShell Script
问题描述
如何从 PowerShell 脚本调用基于休息的 API 并处理 Json 答案?
您想要的是 PowerShell 3 及其 Invoke-RestMethod
、ConvertTo-Json
和 ConvertFrom-Json
cmdlet.您的代码最终将如下所示:
$stuff = Invoke-RestMethod -Uri $url -Method Get;
甚至不需要在结果 $stuff
上调用 ConvertFrom-Json
=> 它已经是可用的非字符串格式.>
请参阅 http://technet.microsoft.com/en-us/Library/hh849971.aspx 了解详情.
How can I call a rest based API from a PowerShell script and process the Json answer?
What you want is PowerShell 3 and its Invoke-RestMethod
, ConvertTo-Json
, and ConvertFrom-Json
cmdlets. Your code will end up looking like:
$stuff = Invoke-RestMethod -Uri $url -Method Get;
and there shouldn't even be a need to invoke ConvertFrom-Json
on the resulting $stuff
=> it's already in a usable non-string format.
See http://technet.microsoft.com/en-us/Library/hh849971.aspx for details.
这篇关于从 PowerShell 脚本调用 REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!