Created
April 5, 2024 19:44
-
-
Save chadmando/437926b001716b679c17021ee65c1992 to your computer and use it in GitHub Desktop.
Device Enrollment Script for AAD Joined Machine that were not enrolled in Intune upon setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Intially copied from this article https://call4cloud.nl/2020/05/intune-auto-mdm-enrollment-for-devices-already-azure-ad-joined/ | |
# "The Improved One" | |
# Set MDM Enrollment URL's | |
$key = 'SYSTEM\CurrentControlSet\Control\CloudDomainJoin\TenantInfo\*' | |
try{ | |
$keyinfo = Get-Item "HKLM:\$key" | |
} | |
catch{ | |
Write-Host "Tenant ID is not found!" | |
exit 1001 | |
} | |
$url = $keyinfo.name | |
$url = $url.Split("\")[-1] | |
$path = "HKLM:\SYSTEM\CurrentControlSet\Control\CloudDomainJoin\TenantInfo\$url" | |
if(!(Test-Path $path)){ | |
Write-Host "KEY $path not found!" | |
exit 1001 | |
}else{ | |
try{ | |
Get-ItemProperty $path -Name MdmEnrollmentUrl | |
} | |
catch{ | |
Write_Host "MDM Enrollment registry keys not found. Registering now..." | |
New-ItemProperty -LiteralPath $path -Name 'MdmEnrollmentUrl' -Value 'https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc' -PropertyType String -Force -ea SilentlyContinue; | |
New-ItemProperty -LiteralPath $path -Name 'MdmTermsOfUseUrl' -Value 'https://portal.manage.microsoft.com/TermsofUse.aspx' -PropertyType String -Force -ea SilentlyContinue; | |
New-ItemProperty -LiteralPath $path -Name 'MdmComplianceUrl' -Value 'https://portal.manage.microsoft.com/?portalAction=Compliance' -PropertyType String -Force -ea SilentlyContinue; | |
} | |
finally{ | |
# Trigger AutoEnroll with the deviceenroller | |
try{ | |
C:\Windows\system32\deviceenroller.exe /c /AutoEnrollMDM | |
Write-Host "Device is performing the MDM enrollment!" | |
exit 0 | |
} | |
catch{ | |
Write-Host "Something went wrong (C:\Windows\system32\deviceenroller.exe)" | |
exit 1001 | |
} | |
} | |
} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment