# Fixing Windows clients Intune automatic enrollment issues using PowerShell

If you are using automatic enrollment of your clients to Intune (via GPO or SCCM), you've probably encountered a situation when some of the clients failed to enroll. You could find this out by accident or by using my [Intune clients report](https://doitpsway.com/get-overall-status-of-your-clients-in-ad-aad-intune-and-sccm-services).

And I am talking about situations when all prerequisites are met and 95% of your clients have enrolled without any issues 😀.

I was facing such issue for several weeks now, but finally, I manage to create a working PowerShell function [Reset-IntuneEnrollment](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Reset-IntuneEnrollment.ps1) that solves all enrollment issues (at least for us). Hopefully, it will help you too 👍

**Reset-IntuneEnrollment ** function will:
 - check actual device Intune status
 - invoke Hybrid AzureAD join reset
 - remove device record(s) from Intune
 - remove local client Intune enrollment data
 - invoke Intune re-enrollment

> 
Btw this [DSRegTool PowerShell script](https://github.com/mzmaili/DSRegTool) can help you too diagnose your registration/enrollment problems. 

---

# Prerequisites
- admin credentials for your Intune environment
- admin rights
- PowerShell modules
 - Microsoft.Graph.Intune
 - ActiveDirectory
- my custom PowerShell functions (I've added them to function body):
 - [Get-IntuneEnrollmentStatus](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Get-IntuneEnrollmentStatus.ps1) 
 - [Reset-HybridADJoin](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Reset-HybridADJoin.ps1) 
 - [Connect-Graph](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Connect-Graph.ps1) 
   - [New-GraphAPIAuthHeader](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/New-GraphAPIAuthHeader.ps1)
 - [Invoke-MDMReenrollment](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Invoke-MDMReenrollment.ps1) (this one is based on work of MauriceDaly)
 - [Get-IntuneLog](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Get-IntuneLog.ps1) 

> 
These custom functions can be used on their own and can be helpful too!

---

# Usage
- Make sure you meet all [prerequisites](#prerequisites)
- Download [Reset-IntuneEnrollment](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Reset-IntuneEnrollment.ps1) script
- Dot source downloaded script
- Call function **Reset-IntuneEnrollment**

Result of calling [Reset-IntuneEnrollment](https://github.com/ztrhgf/useful_powershell_functions/blob/master/INTUNE/Reset-IntuneEnrollment.ps1) function can look like this:
![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1634147924384/_bi0Dd1xx.png)

Enjoy 👍

