Unable to set the scope to the subscription.
$Subscription = Get-AzureRmSubscription -SubscriptionName <Subscription Name>
$Subscription.ResourceId. ---->This is a Null value.
So the below doesn't work
New-AzureRmPolicyAssignment -Name 'Allow resource creation only in United States data centers' -PolicyDefinition $Policy -Scope $Subscription.ResourceId -Verbose
I tried with Subscription id. And that doesn't work either.
Error: The request did not have a provided subscription. All requests must have an associated subscription Id.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@Ayanmullick Thank you for the detailed feedback. We are actively investigating and will get back to you soon.
@Ayanmullick Couple quick questions for you to help on this...
$PSVersionTable.PSVersion)?Get-AzureRmSubscription, did you get any errors?My guess is that you are running PowerShell locally and it looks like the directions are missing performing authentication to Azure first (using Connect-AzureRmAccount). I'd like to verify that with you and then get the article updated with that missing step. Thanks!
@MicrosoftDocs/azure-cxp-triage Please assign to me, and #in-progress.
Major : 5
Minor : 1
Build : 16299
Revision : 637
MajorRevision : 0
MinorRevision : 637
No, I haven't installed it.
I am running it locally. However, I am authenticated into Azure with Login-AzureRMAccount. I get the context of the desired subscription when I run Get-AzureRmContext.
@Ayanmullick Can you validate you having Azure PowerShell 6.3.0+ with Get-Module -Name AzureRM.profile? Please update to the latest, currently 6.10.0, using these directions and see if it is still not working. This might simply be an issue of an old install of Azure PowerShell.
To update this item, the issue is that the example is for Resource Groups and uses Get-AzureRmResourceGroup. That cmdlet returns an object with property ResourceId which has the full path resource identifier that the -Scope parameter expects. @Ayanmullick was trying to set the scope to a Subscription. Get-AzureRmSubscription returns a property Id, but it is not the full path. Using it with scope requires prepending it such that /subscriptions/<subId>/ is passed to -Scope on New-AzureRmPolicyAssignment.
I have two actions for this based on suggestion from @Ayanmullick:
@MicrosoftDocs/azure-cxp-triage Please change this label from 'product-question' to 'doc-enhancement'. I'll leave the issue open until the doc is updated with the two mentioned actions.
@Ayanmullick The updated article for this request should post this morning. Note that I didn't update the Quickstart since that is designed to take you through a specific experience. Instead, the update will provide clarity for subscriptions and management groups on Programmatically create policies. The merge will automatically close this, but if you don't feel that update provides the information you were looking for, please respond back and let us know. Thanks again!
Most helpful comment
To update this item, the issue is that the example is for Resource Groups and uses
Get-AzureRmResourceGroup. That cmdlet returns an object with propertyResourceIdwhich has the full path resource identifier that the -Scope parameter expects. @Ayanmullick was trying to set the scope to a Subscription.Get-AzureRmSubscriptionreturns a propertyId, but it is not the full path. Using it with scope requires prepending it such that/subscriptions/<subId>/is passed to -Scope onNew-AzureRmPolicyAssignment.I have two actions for this based on suggestion from @Ayanmullick:
@MicrosoftDocs/azure-cxp-triage Please change this label from 'product-question' to 'doc-enhancement'. I'll leave the issue open until the doc is updated with the two mentioned actions.