Forum Discussion
ddickinsonBHCET
May 21, 2025Copper Contributor
User Profile Deletion
Hi,
I have encountered an error when using Intune to delete user profiles. I am new to this and have put bits and pieces together from multiple sources to try and compile a script.
I am using a Detect and Remediation Script deployed via Devices > Scrips and Remediation in Intune, to Windows 10 Enterprise 22H2 and Windows 11 Enterprise 24H2. I will attach scripts at the end.
My issue is, the scripts detect and remediate as intended on devices that i have recently enrolled. However, we have devices that will have been enrolled in 2023 which doesn't seem to allow the scripts to run. If I then run an autopilot reset on the device, the scripts work fine.
The scripts essentials look for user profiles in C:\Users and remove them if they are older than 1 hour. We want to keep disk space as free as possible especially on the lower spec devices. It ignores SYSTEM and any Admin user folder, as we have a separate script to delete the LAPSAdmin only at 8pm, when the workplace is closed. Note: The LAPSAdmin script worked on the older devices before the where autopilot reset.
Does anyone know why this could be the case? Does the 1 hour check have issues reaching profiles that are over 2 years old or is there an issue in the script.
Thanks,
Dean
4 Replies
Sort By
- Chris_Apps4RentCopper Contributor
Hey Dean,
The script works after an Autopilot reset because older devices likely have issues with the Intune Management Extension or it's running the script in the wrong context (user instead of system).
It's not the 1-hour check — the script just isn’t running properly on those older setups.
Try:
- Making sure the script runs as system
- Checking the Intune agent health
- Reinstalling the agent if needed
That should fix it!
- Matt-Apps4RentCopper Contributor
Your script works on new devices but fails on older ones likely because older Intune-enrolled devices might not have the remediation script permissions or setup applied properly. An Autopilot reset refreshes Intune configurations, which is why it starts working again.
- ddickinsonBHCETCopper Contributor
Is there way to check/confirm this on a machine to compare it to newer enrolled device, would be interesting to see if this is the reason.
Thanks for your reply!
- Luca_Scarano_TheItalianWayIron Contributor
Hi,
I answered in the duplicated post User Profile Deletion | Microsoft Community Hub.
If possible, better to post script as code, not as an image.
Regards