diff --git a/CHANGELOG.md b/CHANGELOG.md index 337fdb5e77..e97c7071fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change log for Microsoft365DSC +# UNRELEASED +* MISC + * Added checks in New-M365DSCConnection to ensure beta MSGraph profile is correctly set when requested + FIXES [#2942](https://github.com/microsoft/Microsoft365DSC/issues/2942) + # 1.23.308.1 * AADAdministrativeUnit diff --git a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 index b6fc9b3aa1..c4f67680e1 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 @@ -1594,6 +1594,13 @@ function New-M365DSCConnection -Credential $InboundParameters.Credential ` -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'Credential') try @@ -1617,6 +1624,13 @@ function New-M365DSCConnection -Url $Url ` -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'Credential') try @@ -1646,6 +1660,13 @@ function New-M365DSCConnection -Credential $InboundParameters.Credential ` -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'CredentialsWithApplicationId') try @@ -1669,6 +1690,13 @@ function New-M365DSCConnection -Url $Url ` -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'CredentialsWithApplicationId') try @@ -1703,6 +1731,12 @@ function New-M365DSCConnection -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'ServicePrincipalWithPath') $data.Add('Tenant', $InboundParameters.TenantId) Add-M365DSCTelemetryEvent -Data $data -Type 'Connection' @@ -1762,6 +1796,13 @@ function New-M365DSCConnection -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName } + + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile-Name $ProfileName + } + $data.Add('ConnectionType', 'Credential') try { @@ -1788,6 +1829,13 @@ function New-M365DSCConnection -Url $Url ` -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + } $data.Add('ConnectionType', 'ServicePrincipalWithPath') $data.Add('Tenant', $InboundParameters.TenantId) @@ -1811,6 +1859,12 @@ function New-M365DSCConnection -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'ServicePrincipalWithSecret') $data.Add('Tenant', $InboundParameters.TenantId) Add-M365DSCTelemetryEvent -Data $data -Type 'Connection' @@ -1826,6 +1880,12 @@ function New-M365DSCConnection -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'ServicePrincipalWithSecret') $data.Add('Tenant', $InboundParameters.TenantId) Add-M365DSCTelemetryEvent -Data $data -Type 'Connection' @@ -1843,6 +1903,12 @@ function New-M365DSCConnection -ProfileName $ProfileName ` -Url $Url + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'ServicePrincipalWithThumbprint') $data.Add('Tenant', $InboundParameters.TenantId) Add-M365DSCTelemetryEvent -Data $data -Type 'Connection' @@ -1859,6 +1925,12 @@ function New-M365DSCConnection -SkipModuleReload $Global:CurrentModeIsExport ` -ProfileName $ProfileName + #2942 - check correct profile applied + if (($ProfileName -ne $global:MSCloudLoginConnectionProfile.MicrosoftGraph.ProfileName) -and ($Workload -eq 'MicrosoftGraph') ) + { + Select-MgProfile -Name $ProfileName + } + $data.Add('ConnectionType', 'ManagedIdentity') $data.Add('Tenant', $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.TenantId) Add-M365DSCTelemetryEvent -Data $data -Type 'Connection'