好的,我已经设法将2个XML请求拼凑在一起,这些请求返回了我想最终放入CSV的信息。我需要一些帮助来循环其中一个,我已经尝试了各种For Each循环等但我似乎并没有让它发挥作用。我不确定是否有更好/更有效的方式来提出请求,欢迎任何建议。
$username = "abc"
$password = "mypassword"
$encoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))
$headers = @{Authorization = "Basic " + $encoded}
$ConnectionURI = "https://api.myisp.net/xml/stable/ListConnections.php?liveorceased=live&fields=Customer Ref"
$GetConnections = Invoke-RestMethod -Uri $ConnectionURI -Headers $headers
$ConnectionList = $GetConnections.ResponseBlock.Response.OperationResponse.ADSLAccount
$ConDetailsURI = "https://api.myisp.net/xml/stable/AdslAccount.php?ref=" + $Connections
$details = Invoke-RestMethod -Uri $ConDetailsURI -Headers $headers
$details.ResponseBlock.Response.OperationResponse.ADSLAccount |
Select OurRef, Telephone, NAT, IPAddress, FullUsername, Status, CBUK,
Downstream, Upstream
$ConnectionList
返回以下内容:
CustomerRef ----------- ADSL123456 ADSL789101 ADSL000001 ADSL007111 ADSL111111 ADSL222222 ADSL333333 ADSL444444 ADSL555555 ADSL666666 ADSL777777 ADSL888888 ADSL999999
我想从https://api.myisp.net/xml/stable/AdslAccount.php?ref=" + $ConnectionList
请求详细信息。
返回$details
的示例:
OurRef : ADSL123456 Telephone : 0123456789 NAT : Y IPAddress : 70.1.2.3 FullUsername : 0123456789@vmyisp.net Status : Installed CBUK : BBEU21234561 Downstream : 80Mbit/s Upstream : 20Mbit/s