Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.21k stars 3.81k forks source link

Azure Gov: Get-AzPolicyAssignment not working #25483

Open PaulHCode opened 2 months ago

PaulHCode commented 2 months ago

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

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

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

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

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 <ScriptBlock>, C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\custom\Get-AzPolicyAssignment.ps1: line 260
                   at Get-AzPolicyAssignment<Process>, C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\custom\Get-AzPolicyAssignment.ps1: line 261
                   at Get-AzPolicyAssignment<Process>, C:\PowerShell\Modules\Az.Resources\7.1.0\Policy.Autorest\exports\ProxyCmdletDefinitions.ps1: line 210
                   at <ScriptBlock>, <No file>: line 1
mentat9 commented 1 month ago

This is now fixed: the new API version is rolled out: please retry. IMPORTANT: it will only work from a clean shell. The same issue will continue to repro in any shell that loaded the Az.Resources/Az.Accounts modules prior to the new API version rollout.