从 PowerShell 脚本调用 REST API [英] Call REST API from PowerShell Script

查看:63
本文介绍了从 PowerShell 脚本调用 REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 PowerShell 脚本调用基于休息的 API 并处理 Json 答案?

解决方案

您想要的是 PowerShell 3 及其 Invoke-RestMethodConvertTo-JsonConvertFrom-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆