Open RobGANA opened 6 months ago
Hi there - I got the same issue but am having trouble implementing your fix. Can you provide the code for your updated EnterprisePolicyOperations.ps1?
thanks
@RobGANA I have the same problem, I've updated the script but I'm still running into the same problem as mentioned in this issue (https://github.com/microsoft/PowerApps-Samples/issues/624). Do you have the updated script so I can try that?
@robjdav and @RyC67,
In EnterprisePolicyOperations.ps1, I altered line 27
function PutEnterprisePolicy($subscriptionId, $resourceGroup, $body)
and I added a new line before line 32
Set-AzContext -Subscription $subscriptionId
In CreateSubnetInjectionPolicy.ps1, I altered line 86
$result = PutEnterprisePolicy $subscriptionId $resourceGroup $body
That's all there was to it. The subscription ID was already a parameter of the CreateSubnetInjectionPolicy script. It just needed to be passed to and used in the EnterprisePolicyOperations script.
thanks!
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 policySubnet Injection Enterprise policy not created`