小编Sea*_*ner的帖子

Powershell Invoke-RestMethod

我正在尝试创建一个powershell脚本来访问DYN的API并对我使用/测试的DNS区域执行检查/更新.

我正在关注他们的API详细信息,这是第一个链接,https://help.dyn.com/session-log-in/

这是我编写的REST脚本的开头:

$url = "https://api2.dynect.net/REST/Session/"
$body = @{customer_name='mahcompany';user_name='mahname';password='mahpass'}
Invoke-RestMethod -Method Post -Uri $url  -Body $body
Run Code Online (Sandbox Code Playgroud)

这会产生以下结果:

Invoke-RestMethod:远程服务器返回错误:(406)Not Acceptable.在行:12 char:9 + $ test = Invoke-RestMethod -Method Post -Uri $ url -Body $ body + ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation :( System.Net.HttpWebRequest:HttpWebRequest)[Invoke-> RestMethod], WebException + FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

根据DYN信息,这应该是一个JSON查询,所以我尝试了使用CURL作为基础的DYN的其他几个例子:

$json = @"{"customer_name":"yourcustomer","user_name":"youruser","password":"yourpass"}' 
Run Code Online (Sandbox Code Playgroud)

然而,这也不起作用.

任何人都能指出我在正确的方向吗?这不是那么疯狂,我只是试图将参数传递给rest-method查询字符串.在这一点上,非常感谢任何帮助.

-Sean

api rest powershell

4
推荐指数
1
解决办法
1万
查看次数

Powershell:比较数组中的多个值

我对Powershell有另一个棘手的问题.我有一个约4000个条目的列表,其中我有以下详细信息:

<Computername> | <Username> | <StartDate> | <LastDate> | <IDNum>
computer1      | jsmith     | 4/12/12     | 4/12/13    | 52648
computer1      | jsmith     | 4/12/12     | -          | 52649
computer1      | jsmith     | 4/12/12     | 8/7/13     | 52644
computer2      | hreid      | 2/5/12      | 8/5/13     | 52396
computer2      | hreid      | 4/10/12     | 5/18/13    | 52300
computer3      | mdrake     | 2/10/11     | 12/18/12   | 52590
computer3      | mdrake     | 5/10/11     | 3/20/12    | 52593
Run Code Online (Sandbox Code Playgroud)

它是一个CSV,我试图找到一种比较Computername和LastDate字段的方法,并吐出最近一行的列表以及相关的computername值.我能够将CSV读入变量,但是我对get-member值和每个循环都有一段时间.

理想情况下,输出看起来像这样:

<Computername> | <Username> | <StartDate> …
Run Code Online (Sandbox Code Playgroud)

arrays powershell comparison

1
推荐指数
1
解决办法
1452
查看次数

标签 统计

powershell ×2

api ×1

arrays ×1

comparison ×1

rest ×1