Forum Discussion
Device - Removal
hi Guys
Hope someone can help i am looking to removed retired devices from Intune and from Azure AD , i know they are a powershell script any advise would be great , even if you can point a script to remove devices from a exported CSV file that would be perfect
Thanks
- almennnBrass Contributor
Hi GrantBradley,
As Ethan Stern said, device cleanup rules are a great way of getting rid of stale devices from Intune and devices which has been unenrolled are automatically deleted from Intune.
Another way of deleting stale devices is via Intune PowerShell SDK. Before using this you have to install the module,
Install-Module -Name Microsoft.Graph.Intune
Here is a simple example of removing devices which has not synced for 60 days:PS C:\Windows\system32> $device = Get-IntuneManagedDevice -Select lastSyncDateTime, id | Where {($_.lastSyncDateTime -lt (Get-Date).AddDays(-60))} | foreach {$_.id}
PS C:\Windows\system32> ForEach-Object {Remove-IntuneManagedDevice -managedDeviceId $device}To delete stale objects from AzureAD see this docs page:
https://docs.microsoft.com/sv-se/azure/active-directory/devices/manage-stale-devices
- Ethan SternIron Contributor
GrantBradley Hi Grant, have you tried using clean up rules? https://docs.microsoft.com/en-us/intune/devices-wipe#automatically-delete-devices-with-cleanup-rules
- GrantBradleyCopper Contributor
Hi Guys
thanks for the advise on the issues are they any other ways you know of bulk removing devices from azure i see i can remove it from intune via powershell or rule but are they anything for azure ad
Thanks
Grant
- Ethan SternIron Contributor
GrantBradley Hi Grant, there are some cmdlets for removing from Azure AD- https://docs.microsoft.com/en-us/powershell/module/msonline/remove-msoldevice?view=azureadps-1.0
Is that what you were thinking of?
- GrantBradleyCopper Contributor
hi Ethan
i am already aware of that currently it is handy for removing one device but i am looking to remove in bulk if that is possible as devices have built over time and had not been removed
Thanks
Grant
- mark-derouenBrass ContributorI needed to deleted all personal windows devices from Intune
I used the following command to get a list of all personally owned windows 10 devices.
Get-IntuneManagedDevice | Get-MSGraphAllPages | Out-GridView
Next I took the list of id's for the devices I needed and used the code below to delete them.
Connect-msgraph
# List of device id's to delete
$ids = get-content "C:\temp\ManagedDeviceIDs.txt"
Foreach ($id in $ids)
{
Write-host " Deleting DeviceName: $id"
Remove-IntuneManagedDevice –managedDeviceId $id –Verbose –ErrorAction Stop
}
Pretty simple stuff. Took me forever to figure it out. Hope this helps someone.