From 2ff07543075d1b89068f49bbeae51901a30b38e2 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 11 Sep 2023 13:14:14 -0400 Subject: [PATCH 1/3] Fixes #3673 --- CHANGELOG.md | 5 ++ .../MSFT_O365OrgSettings.psm1 | 62 ++++--------------- .../Dependencies/Manifest.psd1 | 4 ++ 3 files changed, 21 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2478316770..f0874b1b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,14 @@ * IntuneAppProtectionPolicyAndroid * Added support for 'RequireClass3Biometrics' parameter * Added support for 'RequirePinAfterBiometricChange' parameter +* O365OrgSettings + * Fixes an issue where the wrong Graph URLs were being called for sovereign + clouds. + FIXES [#3673](https://github.com/microsoft/Microsoft365DSC/issues/3673) * DEPENDENCIES * Updated ExchangeOnlineManagement to version 3.3.0. * Updated Microsoft.Graph modules to version 2.5.0. + * Added dependency on Microsoft.Graph.Beta.Reports. * MISC * Improved error logging for methods installing or updating modules. FIXES [#3660](https://github.com/microsoft/Microsoft365DSC/issues/3660) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 index bac50e1040..ceae969552 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 @@ -640,12 +640,12 @@ function Set-TargetResource } # Reports Display Names - $AdminCenterReportDisplayConcealedNamesEnabled = Get-M365DSCOrgSettingsAdminCenterReport + $AdminCenterReportDisplayConcealedNamesEnabled = Get-MgBetaAdminReportSetting Write-Verbose "$($AdminCenterReportDisplayConcealedNamesEnabled.displayConcealedNames) = $AdminCenterReportDisplayConcealedNames" if ($AdminCenterReportDisplayConcealedNames -ne $AdminCenterReportDisplayConcealedNamesEnabled.displayConcealedNames) { Write-Verbose -Message "Updating the Admin Center Report Display Concealed Names setting to {$AdminCenterReportDisplayConcealedNames}" - Update-M365DSCOrgSettingsAdminCenterReport -DisplayConcealedNames $AdminCenterReportDisplayConcealedNames + Update-MgBetaAdminReportSetting -DisplayConcealedNames $AdminCenterReportDisplayConcealedNames } # Apps Installation @@ -1126,44 +1126,6 @@ function Set-M365DSCO365OrgSettingsPlannerConfig $Uri } -function Get-M365DSCOrgSettingsAdminCenterReport -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param() - $VerbosePreference = 'SilentlyContinue' - - try - { - $url = 'https://graph.microsoft.com/beta/admin/reportSettings' - $results = Invoke-MgGraphRequest -Method GET -Uri $url -ErrorAction Stop - return $results - } - catch - { - Write-Verbose -Message "Not able to retrieve Office 365 Report Settings. Please ensure correct permissions have been granted." - return $null - } -} - -function Update-M365DSCOrgSettingsAdminCenterReport -{ - [CmdletBinding()] - [OutputType([Void])] - param( - [Parameter(Mandatory = $true)] - [System.Boolean] - $DisplayConcealedNames - ) - $VerbosePreference = 'SilentlyContinue' - $url = 'https://graph.microsoft.com/beta/admin/reportSettings' - $body = @{ - "@odata.context" ="https://graph.microsoft.com/beta/$metadata#admin/reportSettings/$entity" - displayConcealedNames = $DisplayConcealedNames - } - Invoke-MgGraphRequest -Method PATCH -Uri $url -Body $body | Out-Null -} - function Get-M365DSCOrgSettingsInstallationOptions { [CmdletBinding()] @@ -1177,7 +1139,7 @@ function Get-M365DSCOrgSettingsInstallationOptions try { - $url = 'https://graph.microsoft.com/beta/admin/microsoft365Apps/installationOptions' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/microsoft365Apps/installationOptions' $results = Invoke-MgGraphRequest -Method GET -Uri $url return $results } @@ -1205,7 +1167,7 @@ function Update-M365DSCOrgSettingsInstallationOptions try { - $url = 'https://graph.microsoft.com/beta/admin/microsoft365Apps/installationOptions' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/microsoft365Apps/installationOptions' Invoke-MgGraphRequest -Method PATCH -Uri $url -Body $Options | Out-Null } catch @@ -1232,7 +1194,7 @@ function Get-M365DSCOrgSettingsForms try { - $url = 'https://graph.microsoft.com/beta/admin/forms/settings' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/forms/settings' $results = Invoke-MgGraphRequest -Method GET -Uri $url -ErrorAction Stop return $results } @@ -1257,7 +1219,7 @@ function Update-M365DSCOrgSettingsForms try { Write-Verbose -Message "Updating Forms Settings" - $url = 'https://graph.microsoft.com/beta/admin/forms/settings' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/forms/settings' Invoke-MgGraphRequest -Method PATCH -Uri $url -Body $Options | Out-Null } catch @@ -1279,7 +1241,7 @@ function Get-M365DSCOrgSettingsDynamicsCustomerVoice try { - $url = 'https://graph.microsoft.com/beta/admin/dynamics/customerVoice' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/dynamics/customerVoice' $results = Invoke-MgGraphRequest -Method GET -Uri $url -ErrorAction Stop return $results } @@ -1303,7 +1265,7 @@ function Update-M365DSCOrgSettingsDynamicsCustomerVoice try { - $url = 'https://graph.microsoft.com/beta/admin/dynamics/customerVoice' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/dynamics/customerVoice' Invoke-MgGraphRequest -Method PATCH -Uri $url -Body $Options | Out-Null } catch @@ -1325,7 +1287,7 @@ function Get-M365DSCOrgSettingsAppsAndServices try { - $url = 'https://graph.microsoft.com/beta/admin/appsAndServices/settings' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/appsAndServices/settings' $results = Invoke-MgGraphRequest -Method GET -Uri $url -ErrorAction Stop return $results } @@ -1349,7 +1311,7 @@ function Update-M365DSCOrgSettingsAppsAndServices try { - $url = 'https://graph.microsoft.com/beta/admin/appsAndServices/settings' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/appsAndServices/settings' Invoke-MgGraphRequest -Method PATCH -Uri $url -Body $Options | Out-Null } catch @@ -1370,7 +1332,7 @@ function Get-M365DSCOrgSettingsToDo try { - $url = 'https://graph.microsoft.com/beta/admin/todo/settings' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/todo/settings' $results = Invoke-MgGraphRequest -Method GET -Uri $url -ErrorAction Stop return $results } @@ -1394,7 +1356,7 @@ function Update-M365DSCOrgSettingsToDo try { - $url = 'https://graph.microsoft.com/beta/admin/todo/settings' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/todo/settings' Invoke-MgGraphRequest -Method PATCH -Uri $url -Body $Options | Out-Null } catch diff --git a/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 b/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 index 7dc6691a13..ef2479fd92 100644 --- a/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 +++ b/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 @@ -44,6 +44,10 @@ ModuleName = 'Microsoft.Graph.Beta.Identity.SignIns' RequiredVersion = '2.5.0' }, + @{ + ModuleName = 'Microsoft.Graph.Beta.Reports' + RequiredVersion = '2.5.0' + }, @{ ModuleName = 'Microsoft.Graph.Beta.Teams' RequiredVersion = '2.5.0' From fb86f9ac0b51d1b928f6f34a6bdf67ce396307f9 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 11 Sep 2023 13:34:55 -0400 Subject: [PATCH 2/3] Update MSFT_O365OrgSettings.psm1 --- .../MSFT_O365OrgSettings.psm1 | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 index ceae969552..5c91a5ecad 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 @@ -1370,4 +1370,42 @@ function Update-M365DSCOrgSettingsToDo } } +function Get-M365DSCOrgSettingsAdminCenterReport +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param() + $VerbosePreference = 'SilentlyContinue' + + try + { + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/reportSettings' + $results = Invoke-MgGraphRequest -Method GET -Uri $url -ErrorAction Stop + return $results + } + catch + { + Write-Verbose -Message "Not able to retrieve Office 365 Report Settings. Please ensure correct permissions have been granted." + return $null + } +} + +function Update-M365DSCOrgSettingsAdminCenterReport +{ + [CmdletBinding()] + [OutputType([Void])] + param( + [Parameter(Mandatory = $true)] + [System.Boolean] + $DisplayConcealedNames + ) + $VerbosePreference = 'SilentlyContinue' + $url = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/admin/reportSettings' + $body = @{ + "@odata.context" = $Global:MSCloudLoginConnectionProfile.MicrosoftGraoh.ResourceUrl + 'beta/$metadata#admin/reportSettings/$entity' + displayConcealedNames = $DisplayConcealedNames + } + Invoke-MgGraphRequest -Method PATCH -Uri $url -Body $body | Out-Null +} + Export-ModuleMember -Function *-TargetResource From d0b3c5c9f3b31aa4a83421ab396b23c469204e5b Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 11 Sep 2023 14:44:43 -0400 Subject: [PATCH 3/3] Update MSFT_O365OrgSettings.psm1 --- .../MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 index 5c91a5ecad..7d51547c81 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_O365OrgSettings/MSFT_O365OrgSettings.psm1 @@ -640,12 +640,12 @@ function Set-TargetResource } # Reports Display Names - $AdminCenterReportDisplayConcealedNamesEnabled = Get-MgBetaAdminReportSetting + $AdminCenterReportDisplayConcealedNamesEnabled = Get-M365DSCOrgSettingsAdminCenterReport Write-Verbose "$($AdminCenterReportDisplayConcealedNamesEnabled.displayConcealedNames) = $AdminCenterReportDisplayConcealedNames" if ($AdminCenterReportDisplayConcealedNames -ne $AdminCenterReportDisplayConcealedNamesEnabled.displayConcealedNames) { Write-Verbose -Message "Updating the Admin Center Report Display Concealed Names setting to {$AdminCenterReportDisplayConcealedNames}" - Update-MgBetaAdminReportSetting -DisplayConcealedNames $AdminCenterReportDisplayConcealedNames + Update-M365DSCOrgSettingsAdminCenterReport -DisplayConcealedNames $AdminCenterReportDisplayConcealedNames } # Apps Installation