Created
April 8, 2026 22:01
-
-
Save bstevens-emporia/313253ca725acc05a8da5eb032203e98 to your computer and use it in GitHub Desktop.
1
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
| runscript -Raw=``` | |
| # 1. Find and remove all MDM enrollments from registry | |
| $enrollPath = 'HKLM:\SOFTWARE\Microsoft\Enrollments' | |
| $statusPath = 'HKLM:\SOFTWARE\Microsoft\Enrollments\Status' | |
| $omadmPath = 'HKLM:\SOFTWARE\Microsoft\Provisioning\OMADM\Accounts' | |
| # Skip the default keys that Windows needs | |
| $skip = @('Context', 'Status', 'ValidNodePaths') | |
| Get-ChildItem $enrollPath -ErrorAction SilentlyContinue | Where-Object { | |
| $skip -notcontains $_.PSChildName | |
| } | ForEach-Object { | |
| $guid = $_.PSChildName | |
| Write-Output "Removing enrollment: $guid" | |
| Remove-Item "$enrollPath\$guid" -Recurse -Force -ErrorAction SilentlyContinue | |
| Remove-Item "$statusPath\$guid" -Recurse -Force -ErrorAction SilentlyContinue | |
| } | |
| # 2. Remove OMADM provisioning accounts | |
| if (Test-Path $omadmPath) { | |
| Get-ChildItem $omadmPath -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force | |
| Write-Output "Cleared OMADM accounts" | |
| } | |
| # 3. Remove scheduled tasks from old MDM | |
| Get-ScheduledTask | Where-Object { $_.TaskPath -match 'EnterpriseMgmt' } | ForEach-Object { | |
| Write-Output "Removing task: $($_.TaskName)" | |
| Unregister-ScheduledTask -TaskName $_.TaskName -Confirm:$false | |
| } | |
| Write-Output "Done. Reboot the machine, then re-enroll Hexnode." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment