Forum Discussion

AEchtermeijer's avatar
AEchtermeijer
Copper Contributor
Apr 21, 2022

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...
  • Harm_Veenstra's avatar
    Apr 25, 2022

    AEchtermeijer

     

    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

Resources