Forum Discussion
Question: Script to remove a specific device from MEM (Intune) and Azure AD
- 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
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
Harm_Veenstra Is there a way to remove devices in bulk via PowerShell or Graph? My company is about to ewaste a large number of devices and would like to know if bulk removal is possible.
- Feb 29, 2024Something like this if you have a file containing just the serial numbers that you want to remove:
foreach ($serialnumber in get-content serialnumbers.txt) {
Get-AutoPilotDevice | Where-Object SerialNumber -eq $serialnumber | Remove-AutopilotDevice
}- 2legit2intuneFeb 29, 2024Copper Contributor
Harm_Veenstra Awesome, thank you! I will give this a shot and report back.
- 2legit2intuneFeb 29, 2024Copper ContributorIt worked, thanks again!