Skip to content

Commit

Permalink
Merge pull request #5629 from niwamo/exportedInstance
Browse files Browse the repository at this point in the history
Export Performance Improvement - Addresses #5615
  • Loading branch information
ykuijs authored Jan 17, 2025
2 parents 48a8b90 + 0364a78 commit 3dd01e3
Show file tree
Hide file tree
Showing 65 changed files with 4,580 additions and 4,415 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
FIXES [#5634](https://github.com/microsoft/Microsoft365DSC/issues/5634)
* M365DSCTelemetryEngine
* Report LCM details only if running as administrator.
* MISC
* Export Performance Improvements
Implements the changes described in [#5615](https://github.com/microsoft/Microsoft365DSC/issues/5615)

# 1.25.115.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,64 +84,58 @@ function Get-TargetResource
)
try
{
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters
}
catch
{
Write-Verbose -Message ($_)
}

#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'
try
{
$getValue = $null
#region resource generator code
if (-not [string]::IsNullOrEmpty($Id))
if (-not $Script:exportedInstance)
{
if ($null -ne $Script:exportedInstances -and $Script:ExportMode)
try
{
$getValue = $Script:exportedInstances | Where-Object -FilterScript { $_.Id -eq $Id }
$ConnectionMode = New-M365DSCConnection -Workload 'MicrosoftGraph' `
-InboundParameters $PSBoundParameters
}
else
catch
{
Write-Verbose -Message ($_)
}

#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'

$getValue = $null
#region resource generator code
if (-not [string]::IsNullOrEmpty($Id))
{
$getValue = Get-MgBetaDirectoryAdministrativeUnit -AdministrativeUnitId $Id -ErrorAction SilentlyContinue
}
}

if ($null -eq $getValue -and -not [string]::IsNullOrEmpty($DisplayName))
{
Write-Verbose -Message "Could not find an Azure AD Administrative Unit by Id, trying by DisplayName {$DisplayName}"
if (-Not [string]::IsNullOrEmpty($DisplayName))
if ($null -eq $getValue -and -not [string]::IsNullOrEmpty($DisplayName))
{
if ($null -ne $Script:exportedInstances -and $Script:ExportMode)
{
$getValue = $Script:exportedInstances | Where-Object -FilterScript { $_.DisplayName -eq $DisplayName }
}
else
Write-Verbose -Message "Could not find an Azure AD Administrative Unit by Id, trying by DisplayName {$DisplayName}"
if (-Not [string]::IsNullOrEmpty($DisplayName))
{
$getValue = Get-MgBetaDirectoryAdministrativeUnit -Filter "DisplayName eq '$DisplayName'" -ErrorAction Stop
}
}
#endregion
if ($null -eq $getValue)
{
Write-Verbose -Message "Could not find an Azure AD Administrative Unit with DisplayName {$DisplayName}"
return $nullResult
}
}
#endregion
if ($null -eq $getValue)
else
{
Write-Verbose -Message "Could not find an Azure AD Administrative Unit with DisplayName {$DisplayName}"
return $nullResult
$getValue = $Script:exportedInstance
}
$Id = $getValue.Id
Write-Verbose -Message "An Azure AD Administrative Unit with Id {$Id} and DisplayName {$DisplayName} was found."
Expand Down Expand Up @@ -1099,6 +1093,7 @@ function Export-TargetResource
AccessTokens = $AccessTokens
}

$Script:exportedInstance = $config
$Results = Get-TargetResource @Params

if ($null -ne $Results.ScopedRoleMembers)
Expand Down
Loading

0 comments on commit 3dd01e3

Please sign in to comment.