Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Fixes #4507

Merged
merged 14 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
Fix issue when asserting TeamsGroupPolicyAssignment configurations by
returning its both mandatory parameters in Get-M365DSCResourceKey
* Fix broken links to integration tests in README.md
* Changing logic to retrieve DSC Resources properties not to use DSC
specific cmdlets.

# 1.24.313.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ function Get-TargetResource
-Source $($MyInvocation.MyCommand.Source) `
-TenantId $TenantId `
-Credential $Credential

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
Expand Down Expand Up @@ -871,7 +870,6 @@ function Export-TargetResource
throw "An error occured in Get-TargetResource, the policy {$($params.displayName)} will not be processed. Refer to the event viewer logs for more information."
}


$Results = Update-M365DSCExportAuthenticationResults -ConnectionMode $ConnectionMode `
-Results $Results
if ($Results.Assignments)
Expand All @@ -891,7 +889,6 @@ function Export-TargetResource
-ModulePath $PSScriptRoot `
-Results $Results `
-Credential $Credential

if ($Results.Assignments)
{
$isCIMArray = $false
Expand Down Expand Up @@ -1034,3 +1031,5 @@ function Get-M365DSCAssignmentsAsHashtable
}
return $CIMAssignmentAsHash
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ function Format-M365DSCString
}
)

# Cache the DSC resource to a script-scope variable.
# This avoids fetching the definition multiple times for the same resource, increasing overall speed.
$ResourcePath = Join-Path -Path $PSScriptRoot `
-ChildPath "../../DSCResources/MSFT_$ResourceName/MSFT_$ResourceName.psm1" `
-Resolve
$commandInfo = Get-Command -Module "MSFT_$ResourceName" -ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.Name -eq 'Get-TargetResource'}
if ($null -eq $commandInfo)
{
# Cache the DSC resource to a script-scope variable.
# This avoids fetching the definition multiple times for the same resource, increasing overall speed.
$ResourcePath = Join-Path -Path $PSScriptRoot `
-ChildPath "../../DSCResources/MSFT_$ResourceName/MSFT_$ResourceName.psm1" `
-Resolve

Import-Module $ResourcePath
$commandInfo = Get-Command -Module "MSFT_$ResourceName" | Where-Object -FilterScript {$_.Name -eq 'Get-TargetResource'}
Import-Module $ResourcePath
$commandInfo = Get-Command -Module "MSFT_$ResourceName" | Where-Object -FilterScript {$_.Name -eq 'Get-TargetResource'}
}

# For each invalid character, look for an instance in the string,
# if an instance is found,
Expand Down
23 changes: 17 additions & 6 deletions Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3378,15 +3378,26 @@ function Get-M365DSCExportContentForResource
$Results = Format-M365DSCString -Properties $Results `
-ResourceName $ResourceName

if ($Script:AllM365DscResources.Count -eq 0)
$primaryKey = ''
$ModuleFullName = "MSFT_" + $ResourceName
$moduleInfo = Get-Command -Module $ModuleFullName -ErrorAction SilentlyContinue
if ($null -eq $moduleInfo)
{
if ($Script:AllM365DscResources.Count -eq 0)
{
$Script:AllM365DscResources = Get-DscResource -Module 'Microsoft365Dsc'
}

$Resource = $Script:AllM365DscResources.Where({ $_.Name -eq $ResourceName })
$Keys = $Resource.Properties.Where({ $_.IsMandatory }) | `
Select-Object -ExpandProperty Name
}
else
{
$Script:AllM365DscResources = Get-DscResource -Module 'Microsoft365Dsc'
$cmdInfo = $moduleInfo | Where-Object -FilterScript {$_.Name -eq 'Get-TargetResource'}
$Keys = $cmdInfo.Parameters.Keys
}

$primaryKey = ''
$Resource = $Script:AllM365DscResources.Where({ $_.Name -eq $ResourceName })
$Keys = $Resource.Properties.Where({ $_.IsMandatory }) | `
Select-Object -ExpandProperty Name
if ($Keys.Contains('IsSingleInstance'))
{
$primaryKey = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
}

Mock -CommandName Remove-MgBetaDeviceManagementDeviceCompliancePolicy -MockWith {
}

Mock -CommandName Get-MgBetaDeviceManagementDeviceCompliancePolicyAssignment -MockWith {

return @()
}
Mock -CommandName Update-DeviceConfigurationPolicyAssignment -MockWith {
}
Expand Down Expand Up @@ -459,7 +464,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
}

It 'Should Reverse Engineer resource from the Export method' {
$result = Export-TargetResource @testParams
$result = Export-TargetResource @testParams -Verbose
$result | Should -Not -BeNullOrEmpty
}
}
Expand Down
158 changes: 0 additions & 158 deletions Tests/Unit/Stubs/Microsoft365.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -42614,164 +42614,6 @@ function Get-MgBetaDeviceManagementDeviceCategory
$HttpPipelineAppend
)
}
function Get-MgBetaDeviceManagementDeviceCompliancePolicy
{
[CmdletBinding()]
param(
[Parameter()]
[System.String[]]
$Property,

[Parameter()]
[PSObject]
$InputObject,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$ProxyUseDefaultCredentials,

[Parameter()]
[System.Int32]
$PageSize,

[Parameter()]
[PSObject]
$HttpPipelinePrepend,

[Parameter()]
[System.Int32]
$Skip,

[Parameter()]
[System.Int32]
$Top,

[Parameter()]
[System.String]
$CountVariable,

[Parameter()]
[System.Uri]
$Proxy,

[Parameter()]
[System.String[]]
$Sort,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$All,

[Parameter()]
[System.String]
$Filter,

[Parameter()]
[System.Management.Automation.PSCredential]
$ProxyCredential,

[Parameter()]
[System.String]
$Search,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$Break,

[Parameter()]
[System.String[]]
$ExpandProperty,

[Parameter()]
[PSObject]
$HttpPipelineAppend,

[Parameter()]
[System.String]
$DeviceCompliancePolicyId
)
}
function Get-MgBetaDeviceManagementDeviceCompliancePolicyAssignment
{
[CmdletBinding()]
param(
[Parameter()]
[System.String[]]
$Property,

[Parameter()]
[PSObject]
$InputObject,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$ProxyUseDefaultCredentials,

[Parameter()]
[System.Int32]
$PageSize,

[Parameter()]
[PSObject]
$HttpPipelinePrepend,

[Parameter()]
[System.Int32]
$Skip,

[Parameter()]
[System.Int32]
$Top,

[Parameter()]
[System.String]
$CountVariable,

[Parameter()]
[System.String]
$DeviceCompliancePolicyAssignmentId,

[Parameter()]
[System.String[]]
$Sort,

[Parameter()]
[System.Uri]
$Proxy,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$All,

[Parameter()]
[System.String]
$Filter,

[Parameter()]
[System.Management.Automation.PSCredential]
$ProxyCredential,

[Parameter()]
[System.String]
$Search,

[Parameter()]
[System.Management.Automation.SwitchParameter]
$Break,

[Parameter()]
[System.String[]]
$ExpandProperty,

[Parameter()]
[PSObject]
$HttpPipelineAppend,

[Parameter()]
[System.String]
$DeviceCompliancePolicyId
)
}
function Get-MgBetaDeviceManagementDeviceConfiguration
{
[CmdletBinding()]
Expand Down
Loading