Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.25k stars 3.85k forks source link

Can Get-AzSubscription provide an -Expand parameter to list its management group ancestors? #12391

Open sscchh2001 opened 4 years ago

sscchh2001 commented 4 years ago

Description of the new feature

Can Get-AzSubscription provide an -Expand parameter to list its management group ancestors? I know that GET https://management.azure.com/subscriptions/{subID}?api-version=2018-11-01&$expand=ancestors provide the ancestor details, could PowerShell provide the same functionality?

Proposed implementation details (optional)

dingmeng-xue commented 4 years ago

@msJinLei , please try the latest API and check if we can get those information?

dingmeng-xue commented 4 years ago

@sscchh2001 , we didn't find expand query parameter on API swagger. How did you know this usage? If it is a formal, we will raise a request to service team to ask them to define this parameter on Swagger. Then, clients can support it.

sscchh2001 commented 4 years ago

@dingmeng-xue , I have found it in https://github.com/Azure/azure-powershell/issues/9799, and tested it working in my environment in Azure China. Please kindly check with service team to enable this parameter, thanks.

scratch85 commented 3 years ago

I would also appreciate this feature in the cmdlet. It is used by Azure Portal as well. When browsing to a specific subscription the following call is made: https://management.azure.com/subscriptions/{SubscriptionId}?api-version=2019-03-01&$expand=ancestors Very likely to show the "Parent management group" in the portal ui. I checked it also using the latest version of the API 2020-01-01 adding it as a parameter works just fine.

Result includes "managementGroupAncestors":

{
  "id": "/subscriptions/....",
  "authorizationSource": "....",
  "managementGroupAncestors": [
    "management-group-level-2",
    "management-group-level-1",
    "{myTenantId}"
  ],
  "managedByTenants": [],
  "subscriptionId": "*****",
  "tenantId": "*****",
  "displayName": "MySubscription",
  "state": "Enabled",
  "subscriptionPolicies": {
    "locationPlacementId": "....",
    "quotaId": "....",
    "spendingLimit": "Off"
  }
}
dingmeng-xue commented 3 years ago

Hi scratch85, all clients respect Swagger definition. Below link shows that parameter is not officially supported. Please raise Github issue to azure-rest-api-specs to ask service team update Swagger file if parameter is formal one. https://github.com/Azure/azure-rest-api-specs/blob/2cd7c6eacc5430d8956885e8d19b87ce3f3ebd6e/specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/subscriptions.json#L95

ghost commented 3 years ago

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

scratch85 commented 3 years ago

As recommended I opened an issue in azure-rest-api-specs but there is no answer/comment to it yet.

dingmeng-xue commented 3 years ago

Hi Scratch85,

For the time being, you can use below script as workaround.

Invoke-AzRestMethod -Method GET -Path "/subscriptions/{SubscriptionId}/?api-version=2019-03-01&$expand=ancestors"
scratch85 commented 3 years ago

Hi Scratch85,

For the time being, you can use below script as workaround.

Invoke-AzRestMethod -Method GET -Path "/subscriptions/{SubscriptionId}/?api-version=2019-03-01&$expand=ancestors"

Thanks!!

Yepp, we do this already but would prefer it to be available via the cmdlet. Btw, it works with api-version=2020-01-01 as well (just to use the latest version).

scratch85 commented 2 years ago

any updates here?

dingmeng-xue commented 2 years ago

Azure PowerShell cmdlet conforms to Swagger spec. We need service to define this parameter. It seems issue is still open.

scratch85 commented 2 years ago

Any news?

scratch85 commented 1 year ago

Any news?

scratch85 commented 1 year ago

Any update here?

dingmeng-xue commented 1 year ago

@scratch85 , no idea whether service will support your requirement. Could you use Invoke-AzRestMethod to call API directly as workaround?

scratch85 commented 1 year ago

@scratch85 , no idea whether service will support your requirement. Could you use Invoke-AzRestMethod to call API directly as workaround?

We do this already, but would appreciate if this finds its way into the official documentation and hopefully the cmdlet supports this parameter than as well. Any chance this could make its way into the powershell Az module?

scratch85 commented 1 year ago

Any update here?

msJinLei commented 1 year ago

Sorry, we cannot support the service API parameter which is not officially defined.

You can take the following step if you really hope it to be included in Azure PowerShell

Hi scratch85, all clients respect Swagger definition. Below link shows that parameter is not officially supported. Please raise Github issue to azure-rest-api-specs to ask service team update Swagger file if parameter is formal one. https://github.com/Azure/azure-rest-api-specs/blob/2cd7c6eacc5430d8956885e8d19b87ce3f3ebd6e/specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/subscriptions.json#L95

msJinLei commented 1 year ago

@Service team. The customer request us to officially support $expand=ancestors for https://management.azure.com/subscriptions/{SubscriptionId}. Could your team help to support it in the swagger spec so that Azure PowerShell can enable this function officially? Thanks