Forum Discussion
AEchtermeijer
Apr 21, 2022Copper Contributor
Question: Script to remove a specific device from MEM (Intune) and Azure AD
I am looking for a script to fully remove an (Autopilot) device from a Microsoft tenant. The goal is to remove a specific device that I have physical access to from both Microsoft Endpoint Manager (I...
- Apr 25, 2022
There's a module for autopilot things here (https://www.powershellgallery.com/packages/WindowsAutoPilotIntune/5.0),
After installing (Install-Module -Name WindowsAutoPilotIntune.), you could use this to remove the device from the Autopilot devices :
Connect-MSGraph Get-AutoPilotDevice | Where-Object SerialNumber -eq (Get-WmiObject -class Win32_Bios).SerialNumber | Remove-AutopilotDevice
This deletes the device based on the serialnumber of the machine that you're logged into, this could take a few minutes to process in the background.
For the removal of the Azure AD device, you can use this:
Connect-Azuread Get-AzureADDevice | Where-Object DisplayName -Match $env:COMPUTERNAME | Remove-AzureADDevice
AEchtermeijer
May 20, 2022Copper Contributor
Harm_Veenstra Just reaching out as we're having some issues with the script you previously shared. In short, when using the 'Remove-AutopilotDevice'-script, we receive an error when the device was pre-provisioned through Autopilot.
It's a "400 Bad Request"-error that reads "Cannot delete device with ztd id [...] and accountId [...] and device Id [...] because it has registration status as Registered with IsManaged status True"
Any tips?
May 20, 2022
Hmmm.. Pre-provisioned is not Azure AD Joined and registered, didn't test it like that... Perhaps you can contact the creator of the script if he has a GitHub page or contact detail in the PowerShell gallery?
- Jun 12, 2023The Intune Connector doesn't have that feature, you have to reset the or remove the computer account prior to deployment
- AkashdhalleJun 12, 2023Copper Contributor
Harm_Veenstra Hi Harm,
I have a question. I want to create a automation where Intune check the AD for Object or Computer already exist before enrolling it. If the computer name is present in AD then first delete it and then enrollment process starts. Do you have any idea if it is possible in Intune?