Created a PowerShell script that will pull SnapMirror information as part of an drive to change our DP SnapMirrors to XDP SnapMirrors. The query returns more than 500 results and so I'm attempting to use the nextTag field to get all the rest. The first query works fine, however, I am getting the following message when I substitute in the nextTag parameter in subsequent queries:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:1 char:11
+ $sminfo = Invoke-RestMethod `
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I assume that I am formatting this incorrectly but can't find documentation on the correct method. Here is my Powershell code:
Do {
if ($null -eq $next) {
$sminfo = Invoke-RestMethod `
-Method Get `
-Credential $global:netappapicred `
-Uri "https://$($APIServer)/api/6.0/ontap/snap-mirrors?relationship_type=data_protection" `
-ContentType "application/json"
$next=$sminfo.result.nextTag
}
else {
$sminfo = Invoke-RestMethod `
-Method Get `
-Credential $global:netappapicred `
-Uri "https://$($APIServer)/api/6.0/ontap/snap-mirrors?nextTag=$($next))" `
-ContentType "application/json"
$next=$sminfo.result.nextTag
}
foreach ($record in $sminfo.result.records) {
$sm = New-Object PSCustomObject
$source = $record.source_location
$destination = $record.destination_location
$type = $record.relationship_type
$sm | Add-Member -Name source -Value $source -MemberType NoteProperty
$sm | Add-Member -Name destination -Value $destination -MemberType NoteProperty
$sm | Add-Member -Name type -Value $type -MemberType NoteProperty
$data_dp.add($sm)
}
} While ($null -NE $next) Any suggestion how I fix this? Using PowerShell 5.1 and the ONTAP API v6.