Skip to content

Commit

Permalink
Merge pull request #4861 from microsoft/Dev
Browse files Browse the repository at this point in the history
Release 1.24.710.2
  • Loading branch information
NikCharlebois authored Jul 11, 2024
2 parents 45286ed + 3ed8f31 commit 0ccb693
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 76 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log for Microsoft365DSC

# 1.24.710.2

* Telemetry
* Fixed error handling on getting roles.

# 1.24.710.1

* AADApplication
Expand Down
4 changes: 2 additions & 2 deletions Modules/Microsoft365DSC/Microsoft365DSC.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 2024-07-10
# Generated on: 2024-07-11

@{

# Script module or binary module file associated with this manifest.
# RootModule = ''

# Version number of this module.
ModuleVersion = '1.24.710.1'
ModuleVersion = '1.24.710.2'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
158 changes: 84 additions & 74 deletions Modules/Microsoft365DSC/Modules/M365DSCTelemetryEngine.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -66,89 +66,61 @@ function Add-M365DSCTelemetryEvent
$TelemetryEnabled = [System.Environment]::GetEnvironmentVariable('M365DSCTelemetryEnabled', `
[System.EnvironmentVariableTarget]::Machine)

if ($Type -eq 'DriftEvaluation')
{
try
{
$hostId = (Get-Host).InstanceId
if ($null -eq $Script:M365DSCCountResourceInstance -or $hostId -ne $Script:M365DSCExecutionContextId)
{
$Script:M365DSCCountResourceInstance = 1
}
else
{
$Script:M365DSCCountResourceInstance++
}

if ($hostId -ne $Script:M365DSCExecutionContextId)
{
$Script:M365DSCExecutionContextId = $hostId
}
$Data.Add('ResourceInstancesCount', $Script:M365DSCCountResourceInstance)
$Data.Add('M365DSCExecutionContextId', $hostId)
}
catch
{
Write-Verbose -Message $_
}
}

try
if ($null -eq $TelemetryEnabled -or $TelemetryEnabled -eq $true)
{
if ($null -ne $Data.ConnectionMode -and $Data.ConnectionMode.StartsWith('Credential'))
if ($Type -eq 'DriftEvaluation')
{
if ($null -eq $Script:M365DSCCurrentRoles -or $Script:M365DSCCurrentRoles.Length -eq 0)
try
{
try
$hostId = (Get-Host).InstanceId
if ($null -eq $Script:M365DSCCountResourceInstance -or $hostId -ne $Script:M365DSCExecutionContextId)
{
Connect-M365Tenant -Workload 'MicrosoftGraph' @Global:M365DSCTelemetryConnectionToGraphParams -ErrorAction SilentlyContinue
$Script:M365DSCCountResourceInstance = 1
}
catch
else
{
Write-Verbose -Message $_
$Script:M365DSCCountResourceInstance++
}
$Script:M365DSCCurrentRoles = @()

$uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + 'v1.0/me?$select=id'
$currentUser = Invoke-MgGraphRequest -Uri $uri -Method GET
$currentUserId = $currentUser.id

$assignments = Get-MgBetaRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$currentUserId'" `
-Property @('RoleDefinitionId', 'DirectoryScopeId') -All

$roles = Get-MgBetaRoleManagementDirectoryRoleDefinition -All `
-Property @('Id', 'DisplayName')
foreach ($assignment in $assignments)
if ($hostId -ne $Script:M365DSCExecutionContextId)
{
$role = $roles | Where-Object -FilterScript {$_.Id -eq $assignment.RoleDefinitionId}
if ($null -ne $role)
{
$Script:M365DSCCurrentRoles += $role.DisplayName + '|' + $assignment.DirectoryScopeId
}
$Script:M365DSCExecutionContextId = $hostId
}
$Data.Add('M365DSCCurrentRoles', $Script:M365DSCCurrentRoles -join ',')
$Data.Add('ResourceInstancesCount', $Script:M365DSCCountResourceInstance)
$Data.Add('M365DSCExecutionContextId', $hostId)
}
else
catch
{
$Data.Add('M365DSCCurrentRoles', $Script:M365DSCCurrentRoles -join ',')
Write-Verbose -Message $_
}
}
elseif ($null -ne $Data.ConnectionMode -and $Data.ConnectionMode.StartsWith('ServicePrincipal'))

try
{
if ($null -eq $Script:M365DSCCurrentRoles -or $Script:M365DSCCurrentRoles.Length -eq 0)
if ($null -ne $Data.ConnectionMode -and $Data.ConnectionMode.StartsWith('Credential'))
{
try
if ($null -eq $Script:M365DSCCurrentRoles -or $Script:M365DSCCurrentRoles.Length -eq 0)
{
Connect-M365Tenant -Workload 'MicrosoftGraph' @Global:M365DSCTelemetryConnectionToGraphParams -ErrorAction Stop
try
{
Connect-M365Tenant -Workload 'MicrosoftGraph' @Global:M365DSCTelemetryConnectionToGraphParams -ErrorAction SilentlyContinue
}
catch
{
Write-Verbose -Message $_
}
$Script:M365DSCCurrentRoles = @()

$sp = Get-MgServicePrincipal -Filter "AppId eq '$($Global:M365DSCTelemetryConnectionToGraphParams.ApplicationId)'" `
-ErrorAction 'SilentlyContinue'
if ($null -ne $sp)
$uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + 'v1.0/me?$select=id'
$currentUser = Invoke-MgGraphRequest -Uri $uri -Method GET
$currentUserId = $currentUser.id

$assignments = Get-MgBetaRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$currentUserId'" `
-Property @('RoleDefinitionId', 'DirectoryScopeId') -All -ErrorAction 'SilentlyContinue'

if ($null -ne $assignments)
{
$assignments = Get-MgBetaRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$($sp.Id)'" `
-Property @('RoleDefinitionId', 'DirectoryScopeId') -All
$roles = Get-MgBetaRoleManagementDirectoryRoleDefinition -All `
$roles = Get-MgBetaRoleManagementDirectoryRoleDefinition -All `
-Property @('Id', 'DisplayName')
foreach ($assignment in $assignments)
{
Expand All @@ -161,24 +133,58 @@ function Add-M365DSCTelemetryEvent
$Data.Add('M365DSCCurrentRoles', $Script:M365DSCCurrentRoles -join ',')
}
}
catch
else
{
Write-Verbose -Message $_
$Data.Add('M365DSCCurrentRoles', $Script:M365DSCCurrentRoles -join ',')
}
}
else
elseif ($null -ne $Data.ConnectionMode -and $Data.ConnectionMode.StartsWith('ServicePrincipal'))
{
$Data.Add('M365DSCCurrentRoles', $Script:M365DSCCurrentRoles -join ',')
if ($null -eq $Script:M365DSCCurrentRoles -or $Script:M365DSCCurrentRoles.Length -eq 0)
{
try
{
Connect-M365Tenant -Workload 'MicrosoftGraph' @Global:M365DSCTelemetryConnectionToGraphParams -ErrorAction Stop
$Script:M365DSCCurrentRoles = @()

$sp = Get-MgServicePrincipal -Filter "AppId eq '$($Global:M365DSCTelemetryConnectionToGraphParams.ApplicationId)'" `
-ErrorAction 'SilentlyContinue'
if ($null -ne $sp)
{
$assignments = Get-MgBetaRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$($sp.Id)'" `
-Property @('RoleDefinitionId', 'DirectoryScopeId') -All -ErrorAction 'SilentlyContinue'
if ($null -ne $assignments)
{
$roles = Get-MgBetaRoleManagementDirectoryRoleDefinition -All `
-Property @('Id', 'DisplayName')
foreach ($assignment in $assignments)
{
$role = $roles | Where-Object -FilterScript {$_.Id -eq $assignment.RoleDefinitionId}
if ($null -ne $role)
{
$Script:M365DSCCurrentRoles += $role.DisplayName + '|' + $assignment.DirectoryScopeId
}
}
$Data.Add('M365DSCCurrentRoles', $Script:M365DSCCurrentRoles -join ',')
}
}
}
catch
{
Write-Verbose -Message $_
}
}
else
{
$Data.Add('M365DSCCurrentRoles', $Script:M365DSCCurrentRoles -join ',')
}
}
}
}
catch
{
Write-Verbose -Message $_
}
catch
{
Write-Verbose -Message $_
}

if ($null -eq $TelemetryEnabled -or $TelemetryEnabled -eq $true)
{
$TelemetryClient = Get-M365DSCApplicationInsightsTelemetryClient

try
Expand Down Expand Up @@ -433,6 +439,10 @@ function Add-M365DSCTelemetryEvent
}
}
}
else
{
return
}
}

<#
Expand Down

0 comments on commit 0ccb693

Please sign in to comment.