azure-scripts icon indicating copy to clipboard operation
azure-scripts copied to clipboard

Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'SkipToken'. Specified method is not supported.

Open chaoscreater opened this issue 1 year ago • 0 comments

Hi, I came across your script "Get-AzureAppGatewayExpiringCertificates" and tried to use it. Keep getting the SkipToken error. If I use just Search-AzGraph @searchParams then it's fine. I haven't looked too much into it yet, but just thought I'd post this here in case you know what's going on.

image

Looks like my $result doesn't have a SkipToken property. I'm guessing when you wrote this, you had a lot of pages in the result. In my case, I have very little data, only 10 elements in the result.

Anyway, I tweaked this a bit and now it works:

$pageSize = 100
$iteration = 0
$searchParams = @{
    Query = 'Resources | where type =~ "Microsoft.Network/applicationGateways" | join kind=leftouter (ResourceContainers | where type=="microsoft.resources/subscriptions" | project subscriptionName=name, subscriptionId) on subscriptionId | project id, subscriptionId, subscriptionName, resourceGroup, name, sslCertificates = properties.sslCertificates | order by id'
    First = $pageSize    
}

$results = @()
do {
    $iteration += 1
    Write-Verbose "Iteration #$iteration"
    $results += Search-AzGraph @searchParams
    if ($results.SkipToken -ne $null) {
    	write-host "More to process!"
        $searchParams.SkipToken = $results.SkipToken
    
    }else{
    
    	write-host "results SkipToken is null"
    }
} while (($results.SkipToken) -ne $null)

chaoscreater avatar Aug 12 '23 13:08 chaoscreater