Azure / Azure/azure-powershell
Azure Gov: Get-AzPolicyAssignment not working
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
In AzureUSGovernment tenants Get-AzPolicyAssignment returns:
`Get-AzPolicyAssignment_Get1: C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\custom\Get-AzPolicyAssignment.ps1:260
Line |
260 | $scriptCmd = {& $wrappedCmd @calledParameters}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The resource type 'policyassignments' could not be found in the namespace 'microsoft.authorization' for api
| version '2023-04-01'. The supported api-versions are
| '2015-10-01-preview,2016-04-01,2016-12-01,2017-06-01-preview,2018-03-01,2018-05-01,2019-01-01,2019-06-01,2019-09-01,2020-03-01,2020-08-01,2020-09-01,2021-06-01,2022-06-01'.
`
This worked in previous versions of the module in AzureUSGovernment.
### Issue script & Debug output
```PowerShell
Get-AzPolicyAssignment
Get-AzPolicyAssignment_List3: C:\\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\custom\Get-AzPolicyAssignment.ps1:260
Line |
260 | $scriptCmd = {& $wrappedCmd @calledParameters}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The resource type 'policyAssignments' could not be found in the namespace 'Microsoft.Authorization' for api
| version '2023-04-01'. The supported api-versions are
| '2015-10-01-preview,2016-04-01,2016-12-01,2017-06-01-preview,2018-03-01,2018-05-01,2019-01-01,2019-06-01,2019-09-01,2020-03-01,2020-08-01,2020-09-01,2021-06-01,2022-06-01'.
PS C:\Users\> Get-AzPolicyAssignment -Debug
begin:Get-AzPolicyAssignment( [Debug, True] ) - (ParameterSet: Default)
process:Get-AzPolicyAssignment( [Debug, True] ) - (ParameterSet: Default)
DEBUG: 1:17:30 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:17:30 PM - GetAzureRMContextCommand begin processing with ParameterSet 'GetSingleContext'.
DEBUG: 1:17:30 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:17:30 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:17:30 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:17:30 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:17:30 PM - GetAzureRMContextCommand end processing.
-> Az.Policy.private\Get-AzPolicyAssignment_List3 ( [Debug, True] [Filter, atScope()] [SubscriptionId, System.Object[]] )
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments?$filter=atScope()&api-version=2023-04-01
DEBUG: RequestCreated: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments?$filter=atScope()&api-version=2023-04-01
DEBUG: HeaderParametersAdded:
DEBUG: 1:17:30 PM - [ConfigManager] Got nothing from [DisableInstanceDiscovery], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.usgovcloudapi.net/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policyAssignments?$filter=atScope()&api-version=2023-04-01
Headers:
x-ms-unique-id : 3
x-ms-client-request-id : eed46767-6044-46fe-a292-827e5479286d
CommandName : &
FullCommandName : Get-AzPolicyAssignment_List3
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v11.1.0,PSVersion/v7.4.3,Az.Policy/7.1.0
Body:
DEBUG: 1:17:30 PM - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
NotFound
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-request-id : ebe2d3dc-4d9b-41a7-8406-d19b79a7dfb6
x-ms-correlation-request-id : ebe2d3dc-4d9b-41a7-8406-d19b79a7dfb6
x-ms-routing-request-id : USDODEAST:20240708T171730Z:ebe2d3dc-4d9b-41a7-8406-d19b79a7dfb6
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Mon, 08 Jul 2024 17:17:30 GMT
Body:
{
"error": {
"code": "InvalidResourceType",
"message": "The resource type 'policyAssignments' could not be found in the namespace 'Microsoft.Authorization' for api version '2023-04-01'. The supported api-versions are '2015-10-01-preview,2016-04-01,2016-12-01,2017-06-01-preview,2018-03-01,2018-05-01,2019-01-01,2019-06-01,2019-09-01,2020-03-01,2020-08-01,2020-09-01,2021-06-01,2022-06-01'."
}
}
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
Get-AzPolicyAssignment_List3: C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\custom\Get-AzPolicyAssignment.ps1:260
Line |
260 | $scriptCmd = {& $wrappedCmd @calledParameters}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The resource type 'policyAssignments' could not be found in the namespace 'Microsoft.Authorization' for api
| version '2023-04-01'. The supported api-versions are
| '2015-10-01-preview,2016-04-01,2016-12-01,2017-06-01-preview,2018-03-01,2018-05-01,2019-01-01,2019-06-01,2019-09-01,2020-03-01,2020-08-01,2020-09-01,2021-06-01,2022-06-01'.
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSResourceNotFoundCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.Resources:7.1.0; CommandName: Get-AzPolicyAssignment; PSVersion: 7.4.3; IsSuccess: False; Duration: 00:00:00.3172155; SanitizeDuration: 00:00:00; Exception: InternalException;
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.4.3
PSEdition Core
GitCommitId 7.4.3
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 3.0.0 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzConte…
Script 7.1.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, G…
```
### Error output
```PowerShell
InnerException : False
Exception : System.Exception: [InvalidResourceType] : The resource type 'policyAssignments' could not be found in the namespace 'Microsoft.Authorization' for api version '2023-04-01'. The supported api-versions
are '2015-10-01-preview,2016-04-01,2016-12-01,2017-06-01-preview,2018-03-01,2018-05-01,2019-01-01,2019-06-01,2019-09-01,2020-03-01,2020-08-01,2020-09-01,2021-06-01,2022-06-01'.
Message : [InvalidResourceType] : The resource type 'policyAssignments' could not be found in the namespace 'Microsoft.Authorization' for api version '2023-04-01'. The supported api-versions are
'2015-10-01-preview,2016-04-01,2016-12-01,2017-06-01-preview,2018-03-01,2018-05-01,2019-01-01,2019-06-01,2019-09-01,2020-03-01,2020-08-01,2020-09-01,2021-06-01,2022-06-01'.
StackTrace :
HelpLink :
ErrorDetails : The resource type 'policyAssignments' could not be found in the namespace 'Microsoft.Authorization' for api version '2023-04-01'. The supported api-versions are
'2015-10-01-preview,2016-04-01,2016-12-01,2017-06-01-preview,2018-03-01,2018-05-01,2019-01-01,2019-06-01,2019-09-01,2020-03-01,2020-08-01,2020-09-01,2021-06-01,2022-06-01'.
ErrorCategory : InvalidOperation: ({ }:<>f__AnonymousType1) [Get-AzPolicyAssignment_List3], Exception
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at , C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\custom\Get-AzPolicyAssignment.ps1: line 260
at Get-AzPolicyAssignment, C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\custom\Get-AzPolicyAssignment.ps1: line 261
at Get-AzPolicyAssignment, C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\exports\ProxyCmdletDefinitions.ps1: line 210
at , : line 1
```
Contributor guide
Research direction
Reproduce Get-AzPolicyAssignment in an AzureUSGovernment tenant with Az.Resources 7.1.0, then inspect Policy.Autorest/custom/Get-AzPolicyAssignment.ps1 around line 260 and exports/ProxyCmdletDefinitions.ps1 around line 210. Compare the generated request with the API versions supported by the reported endpoint; done means the command completes successfully in AzureUSGovernment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100