PowerApps-Samples icon indicating copy to clipboard operation
PowerApps-Samples copied to clipboard

Error: Code=ResourceGroupNotFound in EnterprisePolicyOperations.ps1

Open RobGANA opened this issue 1 month ago • 0 comments

https://github.com/microsoft/PowerApps-Samples/blob/ed3b8662ee839650b54735312a1e902d2ab077dc/powershell/enterprisePolicies/Common/EnterprisePolicyOperations.ps1#L32

When running the CreateSubnetInjectionEnterprisePolicy.ps1 script, I got an error on line 32 stating the resource group wasn't found. After confirming I had input the correct name, I reviewed the code and found that the context appears to be incorrect. I believe the issue is that my default subscription is different than the one I'm running this script against, and the call to the New-AzResourceGroupDeployment commandlet on line 32 of this included script is running against the wrong subscription. To confirm this, I added Set-AzContext -Subscription $subscriptionId just before line 32, added $subscriptionId as an additional parameter to this function, and changed line 86 of CreateSubnetInjectionEnterprisePolicy.ps1 to $result = PutEnterprisePolicy $subscriptionId $resourceGroup $body. This resulted in the policy getting created and the script completing without errors.

Here's an example of what the execution, with errors, looks like: `PS C:\PowerApps-Samples\powershell\enterprisePolicies\SubnetInjection> .\CreateSubnetInjectionEnterprisePolicy.ps1

cmdlet CreateSubnetInjectionEnterprisePolicy at command pipeline position 1 Supply values for the following parameters: (Type !? for Help.) subscriptionId: abcd1234-ab12-ab12-ab12-abcdef123456 resourceGroup: Networking-RG enterprisePolicyName: PowerPlatformSubnetInjection enterprisePolicylocation: unitedstates primaryVnetId: /subscriptions/abcd1234-ab12-ab12-ab12-abcdef123456/resourceGroups/Networking-RG/providers/Microsoft.Network/virtualNetworks/vNet-Primary primarySubnetName: PowerPlatformIntegration secondaryVnetId: /subscriptions/abcd1234-ab12-ab12-ab12-abcdef123456/resourceGroups/Networking-RG/providers/Microsoft.Network/virtualNetworks/vNet-Secondary secondarySubnetName: PowerPlatformIntegration Logging In... Logged In... Creating Enterprise policy... New-AzResourceGroupDeployment: C:\PowerApps-Samples\powershell\enterprisePolicies\Common\EnterprisePolicyOperations.ps1:32 Line | 32 | … $policy = New-AzResourceGroupDeployment -DeploymentName "EPDeployme … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 11:31:22 AM - Error: Code=ResourceGroupNotFound; Message=Resource group 'Networking-RG' could not be found. New-AzResourceGroupDeployment: C:\PowerApps-Samples\powershell\enterprisePolicies\Common\EnterprisePolicyOperations.ps1:32 Line | 32 | … $policy = New-AzResourceGroupDeployment -DeploymentName "EPDeployme … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | The deployment validation failed InvalidOperation: C:\PowerApps-Samples\powershell\enterprisePolicies\Common\EnterprisePolicyOperations.ps1:35 Line | 35 | if ($policy.ProvisioningState.Equals("Succeeded")) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | You cannot call a method on a null-valued expression. Error creating/updating Enterprise policy

Subnet Injection Enterprise policy not created`

RobGANA avatar May 22 '24 18:05 RobGANA