Skip to content

Commit

Permalink
Merge pull request #5317 from NikCharlebois/M365DSCRuleEvaluation
Browse files Browse the repository at this point in the history
M365DSCRuleEvaluation - Renaming Key Property
  • Loading branch information
NikCharlebois authored Nov 1, 2024
2 parents 8842974 + a722f10 commit f4fa175
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
* Initial release.
* Intune workload
* Fixed missing permissions in settings.json
* M365DSCRuleEvaluation
* Changed the name of the Key property from ResourceName to ResourceTypeName.
While this is considered a breaking change, the old property name was
breaking the DSCParser process. The impact of this breaking the parsing
process is important enough to justify an out-of-band breaking change of
this resource.
* SCPolicyConfig
* Initial release.
* SCSensitivityLabel
Expand Down Expand Up @@ -148,6 +154,8 @@
IntuneDeviceEnrollmentStatusPageWindows10, IntuneDiskEncryptionMacOS, IntunePolicySets,
IntuneSettingCatalogCustomPolicyWindows10, M365DSCRGUtil
* Exponential performance improvements by reducing complexity and roundtrips.
* Changed the logic that appends GUID in the resource name when primary key is not found during an
export. We will only append a GUID if the IsSingleInstance property is not found on the resource.
* DEPENDENCIES
* Updated Microsoft.Graph to version 2.24.0.
* Updated Microsoft.PowerApps.Administration.PowerShell to version 2.0.199.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Get-TargetResource
(
[Parameter(Mandatory = $true)]
[System.String]
$ResourceName,
$ResourceTypeName,

[Parameter(Mandatory = $true)]
[System.String]
Expand Down Expand Up @@ -54,7 +54,7 @@ function Set-TargetResource
(
[Parameter(Mandatory = $true)]
[System.String]
$ResourceName,
$ResourceTypeName,

[Parameter(Mandatory = $true)]
[System.String]
Expand Down Expand Up @@ -103,7 +103,7 @@ function Test-TargetResource
(
[Parameter(Mandatory = $true)]
[System.String]
$ResourceName,
$ResourceTypeName,

[Parameter(Mandatory = $true)]
[System.String]
Expand Down Expand Up @@ -153,7 +153,7 @@ function Test-TargetResource
Write-Verbose -Message 'Testing configuration of AzureAD Tenant Details'

$Global:PartialExportFileName = "$((New-Guid).ToString()).partial"
$module = Join-Path -Path $PSScriptRoot -ChildPath "..\MSFT_$ResourceName\MSFT_$ResourceName.psm1" -Resolve
$module = Join-Path -Path $PSScriptRoot -ChildPath "..\MSFT_$ResourceTypeName\MSFT_$ResourceTypeName.psm1" -Resolve
if ($null -ne $module)
{
$params = @{
Expand All @@ -172,7 +172,7 @@ function Test-TargetResource

Write-Verbose -Message "Importing module from Path {$($module)}"
Import-Module $module -Force -Function 'Export-TargetResource' | Out-Null
$cmdName = "MSFT_$ResourceName\Export-TargetResource"
$cmdName = "MSFT_$ResourceTypeName\Export-TargetResource"

[Array]$instances = &$cmdName @params

Expand Down Expand Up @@ -220,7 +220,7 @@ function Test-TargetResource

$message = [System.Text.StringBuilder]::New()
[void]$message.AppendLine("<M365DSCRuleEvaluation>")
[void]$message.AppendLine(" <ResourceName>$ResourceName</ResourceName>")
[void]$message.AppendLine(" <ResourceName>$ResourceTypeName</ResourceName>")
[void]$message.AppendLine(" <RuleDefinition>$RuleDefinition</RuleDefinition>")

if ($instances.Length -eq 0)
Expand Down Expand Up @@ -252,7 +252,7 @@ function Test-TargetResource
[void]$message.AppendLine(" <Match>")
foreach ($validInstance in $validInstances)
{
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceName]$validInstance</ResourceInstanceName>")
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceTypeName]$validInstance</ResourceInstanceName>")
}
[void]$message.AppendLine(" </Match>")
}
Expand All @@ -268,7 +268,7 @@ function Test-TargetResource
[void]$message.AppendLine(" <Match>")
foreach ($validInstance in $validInstances)
{
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceName]$validInstance</ResourceInstanceName>")
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceTypeName]$validInstance</ResourceInstanceName>")
}
[void]$message.AppendLine(" </Match>")
}
Expand All @@ -295,7 +295,7 @@ function Test-TargetResource
[void]$message.AppendLine(" <Match>")
foreach ($validInstance in $validInstances)
{
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceName]$validInstance</ResourceInstanceName>")
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceTypeName]$validInstance</ResourceInstanceName>")
}
[void]$message.AppendLine(" </Match>")
}
Expand All @@ -312,7 +312,7 @@ function Test-TargetResource
[void]$message.AppendLine(" <NotMatch>")
foreach ($invalidInstance in $invalidInstances)
{
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceName]$invalidInstance</ResourceInstanceName>")
[void]$message.AppendLine(" <ResourceInstanceName>[$ResourceTypeName]$invalidInstance</ResourceInstanceName>")
}
[void]$message.AppendLine(" </NotMatch>")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[ClassVersion("1.0.0.0"), FriendlyName("M365DSCRuleEvaluation")]
class MSFT_M365DSCRuleEvaluation : OMI_BaseResource
{
[Key, Description("Name of the resource to monitor")] String ResourceName;
[Key, Description("Name of the resource to monitor")] String ResourceTypeName;
[Required, Description("Specify the rules to monitor the resource for.")] String RuleDefinition;
[Write, Description("Query to check how many instances exist, using PowerShell format")] String AfterRuleCountQuery;
[Write, Description("Credentials of the Azure Active Directory Admin"), EmbeddedInstance("MSFT_Credential")] string Credential;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Configuration Example
{
M365DSCRuleEvaluation 'AllowAnonymousUsersToJoinMeetingAllPolicies'
{
ResourceName = 'TeamsMeetingPolicy'
RuleDefinition = "`$_.AllowAnonymousUsersToJoinMeeting -eq `$true"
Credential = $CredsCredential
ResourceTypeName = 'TeamsMeetingPolicy'
RuleDefinition = "`$_.AllowAnonymousUsersToJoinMeeting -eq `$true"
Credential = $CredsCredential
}
}
}
2 changes: 1 addition & 1 deletion Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3835,7 +3835,7 @@ function Get-M365DSCExportContentForResource
{
$instanceName += "-$primaryKey"
}
else
elseif (-not $Keys.Contains('IsSingleInstance'))
{
$instanceName += "-" + (New-Guid).ToString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Context -Name 'The Rules are successfully evaluated.' -Fixture {
BeforeAll {
$testParams = @{
ResourceName = 'AADConditionalAccessPolicy'
ResourceTypeName = 'AADConditionalAccessPolicy'
RuleDefinition = "`$_.State -eq 'Enabled'"
AfterRuleCountQuery = '-eq 1'
Credential = $Credential
Expand All @@ -61,7 +61,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Context -Name 'The Rules are NOT successfully evaluated.' -Fixture {
BeforeAll {
$testParams = @{
ResourceName = 'AADConditionalAccessPolicy'
ResourceTypeName = 'AADConditionalAccessPolicy'
RuleDefinition = "`$_.State -eq 'Enabled'"
Credential = $Credential
}
Expand Down

0 comments on commit f4fa175

Please sign in to comment.