|
| 1 | +function Invoke-CIPPStandardMDMEnrollmentDuringRegistration { |
| 2 | + <# |
| 3 | + .FUNCTIONALITY |
| 4 | + Internal |
| 5 | + .COMPONENT |
| 6 | + (APIName) MDMEnrollmentDuringRegistration |
| 7 | + .SYNOPSIS |
| 8 | + (Label) Configure MDM enrollment when adding work or school account |
| 9 | + .DESCRIPTION |
| 10 | + (Helptext) Controls the "Allow my organization to manage my device" prompt when adding a work or school account on Windows. This setting determines whether automatic MDM enrollment occurs during account registration. |
| 11 | + (DocsDescription) Controls whether Windows shows the "Allow my organization to manage my device" prompt when users add a work or school account. When set to disabled, this setting prevents automatic MDM enrollment during the account registration flow, separating account registration from device enrollment. This is useful for environments where you want to allow users to add work accounts without triggering MDM enrollment. |
| 12 | + .NOTES |
| 13 | + CAT |
| 14 | + Intune Standards |
| 15 | + TAG |
| 16 | + EXECUTIVETEXT |
| 17 | + Controls automatic device management enrollment during work account setup. When disabled, users can add work accounts to their Windows devices without the prompt asking to allow organizational device management, preventing unintended MDM enrollments on personal or BYOD devices. |
| 18 | + ADDEDCOMPONENT |
| 19 | + {"type":"switch","name":"standards.MDMEnrollmentDuringRegistration.disableEnrollment","label":"Disable MDM enrollment during registration"} |
| 20 | + IMPACT |
| 21 | + Medium Impact |
| 22 | + ADDEDDATE |
| 23 | + 2025-12-15 |
| 24 | + POWERSHELLEQUIVALENT |
| 25 | + Graph API PATCH to mobileDeviceManagementPolicies |
| 26 | + RECOMMENDEDBY |
| 27 | + UPDATECOMMENTBLOCK |
| 28 | + Run the Tools\Update-StandardsComments.ps1 script to update this comment block |
| 29 | + .LINK |
| 30 | + https://docs.cipp.app/user-documentation/tenant/standards/list-standards |
| 31 | + #> |
| 32 | + |
| 33 | + param($Tenant, $Settings) |
| 34 | + $TestResult = Test-CIPPStandardLicense -StandardName 'MDMEnrollmentDuringRegistration' -TenantFilter $Tenant -RequiredCapabilities @('INTUNE_A', 'MDM_Services', 'EMS', 'SCCM', 'MICROSOFTINTUNEPLAN1') |
| 35 | + |
| 36 | + if ($TestResult -eq $false) { |
| 37 | + Write-Host "We're exiting as the correct license is not present for this standard." |
| 38 | + return $true |
| 39 | + } |
| 40 | + |
| 41 | + try { |
| 42 | + $CurrentInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000' -tenantid $Tenant |
| 43 | + } catch { |
| 44 | + $ErrorMessage = Get-CippException -Exception $_ |
| 45 | + Write-LogMessage -API 'Standards' -Tenant $Tenant -Message "Could not get MDM enrollment during registration state for $Tenant. Error: $($ErrorMessage.NormalizedError)" -Sev Error -LogData $ErrorMessage |
| 46 | + return |
| 47 | + } |
| 48 | + |
| 49 | + # Get the current state - if the property doesn't exist, treat as false (default behavior) |
| 50 | + $CurrentState = [bool]$CurrentInfo.isMdmEnrollmentDuringRegistrationDisabled |
| 51 | + $DesiredState = [bool]$Settings.disableEnrollment |
| 52 | + $StateIsCorrect = $CurrentState -eq $DesiredState |
| 53 | + $stateText = $DesiredState ? 'disabled' : 'enabled' |
| 54 | + |
| 55 | + if ($Settings.remediate -eq $true) { |
| 56 | + if ($StateIsCorrect -eq $true) { |
| 57 | + Write-LogMessage -API 'Standards' -tenant $Tenant -message "MDM enrollment during registration is already $stateText" -sev Info |
| 58 | + } else { |
| 59 | + $GraphParam = @{ |
| 60 | + tenantid = $Tenant |
| 61 | + Uri = 'https://graph.microsoft.com/beta/policies/mobileDeviceManagementPolicies/0000000a-0000-0000-c000-000000000000' |
| 62 | + type = 'PATCH' |
| 63 | + Body = (@{'isMdmEnrollmentDuringRegistrationDisabled' = $DesiredState } | ConvertTo-Json) |
| 64 | + } |
| 65 | + |
| 66 | + try { |
| 67 | + New-GraphPostRequest @GraphParam |
| 68 | + Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully $stateText MDM enrollment during registration" -sev Info |
| 69 | + } catch { |
| 70 | + $ErrorMessage = Get-CippException -Exception $_ |
| 71 | + Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to configure MDM enrollment during registration. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + if ($Settings.alert -eq $true) { |
| 77 | + if ($StateIsCorrect -eq $true) { |
| 78 | + Write-LogMessage -API 'Standards' -tenant $tenant -message "MDM enrollment during registration is $stateText as configured" -sev Info |
| 79 | + } else { |
| 80 | + Write-StandardsAlert -message "MDM enrollment during registration is not $stateText" -object @{isMdmEnrollmentDuringRegistrationDisabled = $CurrentState; desiredState = $DesiredState } -tenant $tenant -standardName 'MDMEnrollmentDuringRegistration' -standardId $Settings.standardId |
| 81 | + Write-LogMessage -API 'Standards' -tenant $tenant -message "MDM enrollment during registration is not $stateText" -sev Info |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + if ($Settings.report -eq $true) { |
| 86 | + $FieldValue = $StateIsCorrect ? $true : @{isMdmEnrollmentDuringRegistrationDisabled = $CurrentState; desiredState = $DesiredState } |
| 87 | + Set-CIPPStandardsCompareField -FieldName 'standards.MDMEnrollmentDuringRegistration' -FieldValue $FieldValue -TenantFilter $Tenant |
| 88 | + Add-CIPPBPAField -FieldName 'MDMEnrollmentDuringRegistration' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant |
| 89 | + } |
| 90 | +} |
0 commit comments