Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Code=ResourceGroupNotFound in EnterprisePolicyOperations.ps1 #590

Open
RobGANA opened this issue May 22, 2024 · 0 comments
Open

Error: Code=ResourceGroupNotFound in EnterprisePolicyOperations.ps1 #590

RobGANA opened this issue May 22, 2024 · 0 comments

Comments

@RobGANA
Copy link

RobGANA commented May 22, 2024

$policy = New-AzResourceGroupDeployment -DeploymentName "EPDeployment" -ResourceGroupName $resourceGroup -TemplateFile $tmp.FullName

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`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant