From 9da825ca0f6f2fd8cf5c3aa90c52b130cc172864 Mon Sep 17 00:00:00 2001 From: sebastian claesson Date: Tue, 2 Apr 2024 10:53:18 +0200 Subject: [PATCH] Adding a string match for insufficient permissions --- src/functions/Initialize-AzOpsEnvironment.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/functions/Initialize-AzOpsEnvironment.ps1 b/src/functions/Initialize-AzOpsEnvironment.ps1 index d0939a6b..fb7d8627 100644 --- a/src/functions/Initialize-AzOpsEnvironment.ps1 +++ b/src/functions/Initialize-AzOpsEnvironment.ps1 @@ -119,8 +119,11 @@ $managementGroups = Get-AzManagementGroup -ErrorAction Stop } catch { - Write-AzOpsMessage -LogLevel Warning -LogString 'Initialize-AzOpsEnvironment.ManagementGroup.NoManagementGroupAccess' - return + if ($_.Exception.Message -match 'does not have authorization to perform action ''Microsoft.Management/register/action''') { + Write-AzOpsMessage -LogLevel Warning -LogString 'Initialize-AzOpsEnvironment.ManagementGroup.InsufficientPermissions' + } else { + Write-AzOpsMessage -LogLevel Warning -LogString 'Initialize-AzOpsEnvironment.ManagementGroup.NoManagementGroupAccess' + } } #region Validate root '/' permissions - different methods of getting current context depending on principalType