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

Test-TargetResource Streamlining #5787

Draft
wants to merge 3 commits into
base: Dev
Choose a base branch
from

Conversation

NikCharlebois
Copy link
Collaborator

Pull Request (PR) description

  • Streamlining all Test-TargetResource methods.

This Pull Request (PR) fixes the following issues

  • N/A

Copy link
Collaborator

@FabienTschanz FabienTschanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolute crazy work @NikCharlebois. I added some comments and here's another list of resources that either do something with properties or exclude them from the comparison. This is for information purposes so you can easily disregard it, but I personally think it's important that the comparison is as equal as it gets.

  • AADIdentityAPIConnector --> Password
  • AADRoleAssignmentScheduleRequest --> ScheduleInfo with custom date range logic
  • AADRoleDefinition --> TemplateId
  • AADRoleEligibilityScheduleRequest --> ScheduleInfo, Action, IsValidationOnly, Justification
  • EXODistributionGroup --> OrganizationalUnit
  • EXOSafeLinksPolicy --> UseTranslatedNotificationText
  • EXOTenantAllowBlockListItems --> Entries, ExpirationDate
  • IntuneDeviceConfigurationAdministrativeTemplatePolicyWindows10 --> PolicyConfigurationIngestionType
  • IntuneDeviceConfigurationSCEPCertificatePolicyWindows10 --> RootCertificateDisplayName
  • IntuneDeviceConfigurationWiredNetworkPolicyWindows10 --> 5 different properties
  • IntuneDeviceManagementAndroidDeviceOwnerEnrollmentProfile --> 6 different properties
  • IntuneEndpointDetectionAndResponsePolicy --> ConfigurationBlob
  • IntuneMobileAppsMacOSLobApp --> LargeIcon
  • IntuneMobileAppsWindowsOfficeSuiteApp --> OfficePlatformArchitecture
  • IntuneMobileThreatDefenseConnector --> LastHeartbeatDateTime
  • PPPowerAppsEnvironment --> ProvisionDatabase, LanguageName, CurrencyName
  • SCRoleGroupMember --> Description
  • TeamsClientConfiguration --> RestrictedSenderList
  • TeamsMeetingPolicy --> AllowAnonymousUsersToDialOut, AllowIPVideo, AllowUserToJoinExternalMeeting, ForceStreamingAttendeeMode (deprecated), AllowRecordingStorageOutsideRegion
  • TeamsMessagingPolicy --> Tenant
  • TeamsShiftsPolicy --> EnableShiftPresence
  • TeamsTeam --> GroupID
  • TeamsUpgradePolicy --> Users
  • TeamsUser --> Role

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

Write-Verbose -Message "Testing configuration of the Azure AD Access Review Definition with Id {$Id} and DisplayName {$DisplayName}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be something similar to Write-Verbose -Message "Testing configuration of the resource $ResourceName". Maybe add a Key and AlternateKey parameter for resources that have e.g. a DisplayName as well as an Id property?

.Description
Centralized method to evaluate the result of the various Test-TargetResource functions
#>
function Test-M365DSCTargetResource
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that for whatever reason, there are resources for which specific properties are excluded from comparison. Would you like to just go "with the flow" and see if this is really necessary or build an array with properties to exclude from comparison?

Example with AADEntitlementManagementAccessPackageCatalogResource, it got the following three properties excluded before comparison.

  • AddedBy
  • AddedOn
  • IsPendingOnboarding

$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).clone()
$ValuesToCheck.Remove('Action') | Out-Null
if ($null -ne $CurrentValues.ScheduleInfo -and $null -ne $ValuesToCheck.ScheduleInfo)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we deal with custom comparison logic like here?

$CurrentValues = Get-TargetResource @PSBoundParameters
$ValuesToCheck = ([Hashtable]$PSBoundParameters).Clone()

if ($null -ne $CurrentValues.ScheduleInfo -and $null -ne $ValuesToCheck.ScheduleInfo)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another custom logic comparison.

# Need to remove Identity as Get-ArcConfig doesn't return Identity
$ValuesToCheck.Remove('Identity') | Out-Null

$PSBoundParameters.ArcTrustedSealers = $PSBoundParameters.ArcTrustedSealers -Join ','
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other custom logic here.


if ($TestResult)
{
$TestResult = Compare-SPOTheme -existingThemePalette $currentValues.Palette -configThemePalette $Palette
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom comparison of Palette

$DesiredValues = $PSBoundParameters
if ($null -ne $DesiredValues.EmergencyNumbers -and $DesiredValues.EmergencyNumbers.Count -gt 0)
{
$numbers = Convert-CIMToTeamsEmergencyNumbers -Numbers $DesiredValues.EmergencyNumbers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom conversion in place.

Comment on lines -277 to -280
if ($CurrentValues.SdnApiToken -eq '**********')
{
$CurrentValues.Remove('SdnApiToken') | Out-Null
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the SdnApiToken if it's anonymized.

Comment on lines -414 to -419
if ($null -ne $NormalizationRules)
{
$desiredRules = @()
foreach ($rule in $NormalizationRules)
{
$desiredRule = @{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom conversion in place.

Comment on lines -348 to -354
if ($PSBoundParameters.ContainsKey('UpdateTimeOfDay'))
{
Write-Verbose -Message "Converting UpdateTimeOfDay ($UpdateTimeOfDay) to the current culture format"
$dtUpdateTimeOfDay = [datetime]::Parse($PSBoundParameters.UpdateTimeOfDay)
$PSBoundParameters.UpdateTimeOfDay = $dtUpdateTimeOfDay.ToShortTimeString()
Write-Verbose -Message " Converted value $($PSBoundParameters.UpdateTimeOfDay))"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom conversion in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants