Power shell 与此命令等效的命令

Power shell equivalent command to this command

我使用 ansible tower 配置 linux ec2 实例的回调 url 用户数据:

#!/bin/bash
curl --data "host_config_key=XXXXXXXXXXXXXXXXXXXXXXXXX"           
https://10.XX.XXX.XXX:443/api/v1/job_templates/646/callback/ -k

以上,回调 url 在塔中 phone 运行并取回配置。

如何使用 windows ec2 实例执行此操作, 我如何使用可以放入我的用户数据的 powershell 脚本发送相同类型的请求,可以 phone 在塔中并取回配置。

从 Powershell 版本 3 开始,我们有一个叫做 Invoke-WebRequest 的东西。 你可以利用它的美,完成相应的工作。

$postParams = @{host_config_key='XXXXXXXXXXXXXXXXXXXXXXXXX'}
Invoke-WebRequest -Uri https://10.XX.XXX.XXX:443/api/v1/job_templates/646/callback/ -Method POST -Body $postParams

您可以通过不同的方式使用它。它有很多选择来完成工作。 另一个获取 RSS 提要的好例子:

Invoke-RestMethod -Uri http://blogs.msdn.com/powershell/rss.aspx | Format-Table -Property Title, pubDate

此外,这些是您可以参考的选项:

Invoke-RestMethod [-Method <WebRequestMethod>] [-UseBasicParsing] [-Uri] <Uri>
 [-WebSession <WebRequestSession>] [-SessionVariable <String>] [-Credential <PSCredential>]
 [-UseDefaultCredentials] [-CertificateThumbprint <String>] [-Certificate <X509Certificate>]
 [-UserAgent <String>] [-DisableKeepAlive] [-TimeoutSec <Int32>] [-Headers <IDictionary>]
 [-MaximumRedirection <Int32>] [-Proxy <Uri>] [-ProxyCredential <PSCredential>] [-ProxyUseDefaultCredentials]
 [-Body <Object>] [-ContentType <String>] [-TransferEncoding <String>] [-InFile <String>] [-OutFile <String>]
 [-PassThru] [<CommonParameters>]