Skip to content

Commit

Permalink
Merge pull request #5684 from FabienTschanz/feat/aad-performance
Browse files Browse the repository at this point in the history
Improve performance of AAD resources
  • Loading branch information
NikCharlebois authored Jan 29, 2025
2 parents 29abf3f + 97f6abc commit 2e80c5c
Show file tree
Hide file tree
Showing 25 changed files with 716 additions and 591 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* AADServicePrincipal
* Fixes a regression issue when trying to export instances, the authentication
parameters were no longer returned by the Get-TargetResource function.
* MISC
* AAD Workload
* Improved performance of various resources during export.

# 1.25.122.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,47 +68,54 @@ function Get-TargetResource

try
{
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion
if (-not $Script:exportedInstance)
{
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters

$nullResult = $PSBoundParameters
$nullResult.Ensure = 'Absent'
#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaIdentityGovernanceAccessReviewDefinition -AccessReviewScheduleDefinitionId $Id -ErrorAction SilentlyContinue
#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion

if ($null -eq $getValue)
{
Write-Verbose -Message "Could not find an Azure AD Access Review Definition with Id {$Id}"
$nullResult = $PSBoundParameters
$nullResult.Ensure = 'Absent'

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaIdentityGovernanceAccessReviewDefinition -AccessReviewScheduleDefinitionId $Id -ErrorAction SilentlyContinue

if (-not [System.String]::IsNullOrEmpty($DisplayName))
if ($null -eq $getValue)
{
$getValue = Get-MgBetaIdentityGovernanceAccessReviewDefinition `
-Filter "DisplayName eq '$DisplayName'" `
-ErrorAction SilentlyContinue | Where-Object `
-FilterScript {
$_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.AccessReviewScheduleDefinition'
Write-Verbose -Message "Could not find an Azure AD Access Review Definition with Id {$Id}"

if (-not [System.String]::IsNullOrEmpty($DisplayName))
{
$getValue = Get-MgBetaIdentityGovernanceAccessReviewDefinition `
-Filter "DisplayName eq '$DisplayName'" `
-ErrorAction SilentlyContinue | Where-Object `
-FilterScript {
$_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.AccessReviewScheduleDefinition'
}
}
}
#endregion
if ($null -eq $getValue)
{
Write-Verbose -Message "Could not find an Azure AD Access Review Definition with DisplayName {$DisplayName}."
return $nullResult
}
}
#endregion
if ($null -eq $getValue)
else
{
Write-Verbose -Message "Could not find an Azure AD Access Review Definition with DisplayName {$DisplayName}."
return $nullResult
$getValue = $Script:exportedInstance
}
$Id = $getValue.Id
Write-Verbose -Message "An Azure AD Access Review Definition with Id {$Id} and DisplayName {$DisplayName} was found"
Expand Down Expand Up @@ -814,6 +821,7 @@ function Export-TargetResource
AccessTokens = $AccessTokens
}

$Script:exportedInstance = $config
$Results = Get-TargetResource @Params
$Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode `
-Results $Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,35 @@ function Get-TargetResource
$AccessTokens
)

New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters | Out-Null

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion

$nullResult = $PSBoundParameters
try
{
$instance = Get-MgBetaPolicyAccessReviewPolicy -ErrorAction Stop
if ($null -eq $instance)
if (-not $Script:exportedInstance)
{
New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters | Out-Null

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion

$nullResult = $PSBoundParameters
$instance = Get-MgBetaPolicyAccessReviewPolicy -ErrorAction SilentlyContinue
if ($null -eq $instance)
{
throw 'Could not retrieve the Access Review Policy'
}
}
else
{
throw 'Could not retrieve the Access Review Policy'
$instance = $Script:exportedInstance
}

$results = @{
Expand Down Expand Up @@ -277,7 +284,6 @@ function Export-TargetResource

try
{
$Script:ExportMode = $true
[array] $Script:exportedInstances = Get-MgBetaPolicyAccessReviewPolicy -ErrorAction Stop

$i = 1
Expand Down Expand Up @@ -310,6 +316,7 @@ function Export-TargetResource
AccessTokens = $AccessTokens
}

$Script:exportedInstance = $config
$Results = Get-TargetResource @Params
$Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode `
-Results $Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,39 @@ function Get-TargetResource

try
{
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion
if (-not $Script:exportedInstance)
{
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion

$nullResult = $PSBoundParameters
$nullResult.Ensure = 'Absent'
$nullResult = $PSBoundParameters
$nullResult.Ensure = 'Absent'

$getValue = $null
#region resource generator code
$getValue = Get-MgBetaPolicyActivityBasedTimeoutPolicy -ErrorAction SilentlyContinue
#endregion
if ($null -eq $getValue)
$getValue = $null
#region resource generator code
$getValue = Get-MgBetaPolicyActivityBasedTimeoutPolicy -ErrorAction SilentlyContinue
#endregion
if ($null -eq $getValue)
{
Write-Verbose -Message "Could not find an Azure AD Activity Based Timeout Policy with DisplayName {$DisplayName}"
return $nullResult
}
}
else
{
Write-Verbose -Message "Could not find an Azure AD Activity Based Timeout Policy with DisplayName {$DisplayName}"
return $nullResult
$getValue = $Script:exportedInstance
}
$Id = $getValue.Id
Write-Verbose -Message "An Azure AD Activity Based Timeout Policy with Id {$Id} and DisplayName {$DisplayName} was found."
Expand Down Expand Up @@ -525,6 +532,7 @@ function Export-TargetResource
AccessTokens = $AccessTokens
}

$Script:exportedInstance = $config
$Results = Get-TargetResource @Params
$Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode `
-Results $Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,35 @@ function Get-TargetResource
$AccessTokens
)

New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters | Out-Null

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion

$nullResult = $PSBoundParameters
try
{
$instance = Get-MgBetaPolicyAdminConsentRequestPolicy -ErrorAction Stop
if ($null -eq $instance)
if (-not $Script:exportedInstance)
{
New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters | Out-Null

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion

$nullResult = $PSBoundParameters
$instance = Get-MgBetaPolicyAdminConsentRequestPolicy -ErrorAction SilentlyContinue
if ($null -eq $instance)
{
throw 'Could not retrieve the Admin Consent Request Policy'
}
}
else
{
throw 'Could not retrieve the Admin Consent Request Policy'
$instance = $Script:exportedInstance
}

$reviewersValue = @()
Expand Down Expand Up @@ -431,7 +438,6 @@ function Export-TargetResource

try
{
$Script:ExportMode = $true
[array] $Script:exportedInstances = Get-MgBetaPolicyAdminConsentRequestPolicy -ErrorAction Stop

$i = 1
Expand Down Expand Up @@ -464,6 +470,7 @@ function Export-TargetResource
AccessTokens = $AccessTokens
}

$Script:exportedInstance = $config
$Results = Get-TargetResource @Params
$Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode `
-Results $Results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,41 @@ function Get-TargetResource

try
{
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters
if (-not $Script:exportedInstance)
{
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies
#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion
#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
$CommandName = $MyInvocation.MyCommand
$data = Format-M365DSCTelemetryParameters -ResourceName $ResourceName `
-CommandName $CommandName `
-Parameters $PSBoundParameters
Add-M365DSCTelemetryEvent -Data $data
#endregion

$nullResult = $PSBoundParameters
$nullResult.Ensure = 'Absent'
$nullResult = $PSBoundParameters
$nullResult.Ensure = 'Absent'

$getValue = $null
$getValue = $null

$getValue = Get-MgBetaDirectoryAttributeSet `
-AttributeSetId $Id `
-ErrorAction SilentlyContinue
$getValue = Get-MgBetaDirectoryAttributeSet `
-AttributeSetId $Id `
-ErrorAction SilentlyContinue

if ($null -eq $getValue)
if ($null -eq $getValue)
{
Write-Verbose -Message "Could not find Attribute Set with Id {$Id}"
return $nullResult
}
}
else
{
Write-Verbose -Message "Could not find Attribute Set with Id {$Id}"
return $nullResult
$getValue = $Script:exportedInstance
}
Write-Verbose -Message "Attribute Set with Id {$Id} was found."

Expand Down Expand Up @@ -361,6 +368,7 @@ function Export-TargetResource
AccessTokens = $AccessTokens
}

$Script:exportedInstance = $config
$Results = Get-TargetResource @Params
$Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode `
-Results $Results
Expand Down
Loading

0 comments on commit 2e80c5c

Please sign in to comment.