【问题标题】:Power shell equivalent command to this command此命令的 Powershell 等效命令
【发布时间】:2016-11-27 03:49:25
【问题描述】:
带有回调 url 的用户数据,我用于使用 ansible tower 配置 linux ec2 实例:
#!/bin/bash
curl --data "host_config_key=XXXXXXXXXXXXXXXXXXXXXXXXX"
https://10.XX.XXX.XXX:443/api/v1/job_templates/646/callback/ -k
上面,回调 url 在塔中工作并取回配置。
如何使用 windows ec2 实例执行此操作,
我如何使用可以放入我的用户数据的 powershell 脚本发送相同类型的请求,可以在塔中打电话并取回配置。
【问题讨论】:
标签:
powershell
curl
amazon-ec2
libcurl
ansible-tower
【解决方案1】:
从 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>]