我正在编写一个 powershell 脚本,该脚本显示我通过 GoDaddy 管理的所有 dns 服务器,并查看哪些服务器即将过期。我正在使用 GoDaddy API 和以下代码:
. .\configs\example.com_update_gd_dns_cfg.ps1
Write-Output "example.com"
$headers = @{}
$headers["Authorization"] = 'sso-key ' + $key + ':' + $secret
$result = Invoke-WebRequest -Uri https://api.godaddy.com/v1/domains/example.com/records/A/@ -method get -headers $headers -Body $json
$content = ConvertFrom-Json $result.content
Write-Output $result
Write-Output "------"
Write-Output "";
其中 . .\configs\example.com_update_gd_dns_cfg.ps1 为;
$domain="example.com" # domain
$type="A" # Record type A, CNAME, MX, etc.
$name="@" # name of record to update. Store number.
$ttl=600 # Time to Live min value 600
$port=443 # Required port, Min value 1
$weight=1 # Required weight, Min value 1
$key="key" # key for godaddy developer API - prod
$secret="secret" # secret for godaddy developer API - prod
我只想看到这个回复: 我唯一关心的值是“域”、“名称服务器”和“过期”
由于某种原因,我得到了此响应而不是服务器的响应:
StatusCode : 200
StatusDescription : OK
Content : [{"data":"192.116.71.196","name":"@","ttl":600,"type":"A"}]
RawContent : HTTP/1.1 200 OK
Vary: origin
X-Request-Id: aVPs8XeAu7YVnnVi2Asyds
X-DataCenter: US_EAST_1
Pragma: no-cache
Connection: keep-alive
Content-Length: 60
Cache-Control: max-age=0, no-cache, no-store...
Forms : {}
Headers : {[Vary, origin], [X-Request-Id, aVPs8XeAu7YVnnVi2Asyds], [X-DataCenter, US_EAST_1], [Pragma, no-cache]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 60
我似乎无法得到我想要的答复,我的代码有什么问题?
我试过这个代码;
. .\configs\example_update_gd_dns_cfg.ps1
$headers = @{}
$headers["Authorization"] = 'sso-key ' + $key + ':' + $secret
$result = Invoke-WebRequest -Uri 'https://api.godaddy.com/v1/domains/example.com/records/' -Method Get -Headers $headers
$content = $result.Content | ConvertFrom-Json
$domain = $content[0].data
Write-Output "Name: $name"
Write-Output "Domain: $domain"
Write-Output "Status: $status"
Write-Output "Expires at: $expires"
PowerShell -NoExit
我得到了以下回应;
Name: @
Domain: (example domain)
Status:
Expires at:
为什么它不会打印请求的其余值?