microsoft / PowerApps-Samples

Sample code for Power Apps, including Dataverse, model-driven apps, canvas apps, Power Apps component framework, portals, and AI Builder.
https://docs.microsoft.com/powerapps
MIT License
1.51k stars 1.7k forks source link

Error with polling from NewSubnetInjection.ps1 script #619

Open ArmaanMcleod opened 2 months ago

ArmaanMcleod commented 2 months ago

When choosing to poll with NewSubnetInjection.ps1, there is a failure when converting operational Location to a string.

.\NewSubnetInjection.ps1

cmdlet NewSubnetInjection at command pipeline position 1
Supply values for the following parameters:
environmentId: 00000000-0000-0000-0000-000000000000
policyArmId: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/enterprise-policy-rg/providers/Microsoft.PowerPlatform/enterprisePolicies/power-apps-dev-test-enterprise-policy
Logging In...
Logged In...
Environment reterieved

Enterprise Policy reterieved

WARNING: Resulting JSON is truncated as serialization has exceeded the set depth of 2.
Linking of vnet policy started for environement 00000000-0000-0000-0000-000000000000
Do you want to poll the linking operation (y/n)
y
Polling the link operation every 5 seconds.
InvokeApi: C:\Users\Armaan\Documents\github-repos\PowerApps-Samples\powershell\enterprisePolicies\Common\EnvironmentOperations.ps1:105
Line |
 105 |          $pollResult = InvokeApi -Method GET -Route $operationLink
     |                                                     ~~~~~~~~~~~~~~
     | Cannot process argument transformation on parameter 'Route'. Cannot convert value to type System.String.
Operation polling failed
InvalidOperation: C:\Users\Armaan\Documents\github-repos\PowerApps-Samples\powershell\enterprisePolicies\Common\EnvironmentOperations.ps1:114
Line |
 114 |          if ($operationState.Equals("Failed") -or $operationState.Equa …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
ArmaanMcleod commented 2 months ago

Looks like below lines:

$operationLocation = $headers.'operation-location'
$retryAfter = $headers.'Retry-After'

return an array of one string when -Route is expecting just a singular string.

Getting first item seems to fix it:

$operationLocation = $headers['operation-location'][0]
$retryAfter = $headers['Retry-After'][0]