Device - Removal

%3CLINGO-SUB%20id%3D%22lingo-sub-470419%22%20slang%3D%22en-US%22%3EDevice%20-%20Removal%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-470419%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%20Guys%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20someone%20can%20help%20i%20am%20looking%20to%20removed%20retired%20devices%20from%20Intune%20and%20from%20Azure%20AD%20%2C%20i%20know%20they%20are%20a%20powershell%20script%20any%20advise%20would%20be%20great%20%2C%20even%20if%20you%20can%20point%20a%20script%20to%20remove%20devices%20from%20a%20exported%20CSV%20file%20that%20would%20be%20perfect%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-470419%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EIntune%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-473828%22%20slang%3D%22en-US%22%3ERe%3A%20Device%20-%20Removal%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-473828%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F323263%22%20target%3D%22_blank%22%3E%40GrantBradley%3C%2FA%3E%26nbsp%3B%20Hi%20Grant%2C%20have%20you%20tried%20using%20clean%20up%20rules%3F%26nbsp%3B%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fintune%2Fdevices-wipe%23automatically-delete-devices-with-cleanup-rules%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fintune%2Fdevices-wipe%23automatically-delete-devices-with-cleanup-rules%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-478581%22%20slang%3D%22en-US%22%3ERe%3A%20Device%20-%20Removal%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-478581%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F323263%22%20target%3D%22_blank%22%3E%40GrantBradley%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F185103%22%20target%3D%22_blank%22%3E%40Ethan%20Stern%3C%2FA%3E%26nbsp%3Bsaid%2C%20device%20cleanup%20rules%20are%20a%20great%20way%20of%20getting%20rid%20of%20stale%20devices%20from%20Intune%20and%20devices%20which%20has%20been%20unenrolled%20are%20automatically%20deleted%20from%20Intune.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnother%20way%20of%20deleting%20stale%20devices%20is%20via%20Intune%20PowerShell%20SDK.%20Before%20using%20this%20you%20have%20to%20install%20the%20module%2C%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22pl-c1%22%3EInstall-Module%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pl-k%22%3E-%3C%2FSPAN%3EName%20Microsoft.Graph.Intune%3C%2FPRE%3E%3CDIV%3E%3CDIV%3EHere%20is%20a%20simple%20example%20of%20removing%20devices%20which%20has%20not%20synced%20for%2060%20days%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3EPS%20C%3A%5CWindows%5Csystem32%26gt%3B%20%24device%20%3D%20Get-IntuneManagedDevice%20-Select%20lastSyncDateTime%2C%20id%20%7C%20Where%20%7B(%24_.lastSyncDateTime%20-lt%20(Get-Date).AddDays(-60))%7D%20%7C%20foreach%20%7B%24_.id%7D%3C%2FDIV%3E%3CDIV%3E%3CBR%20%2F%3EPS%20C%3A%5CWindows%5Csystem32%26gt%3B%20ForEach-Object%20%7BRemove-IntuneManagedDevice%20-managedDeviceId%20%24device%7D%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20delete%20stale%20objects%20from%20AzureAD%20see%20this%20docs%20page%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsv-se%2Fazure%2Factive-directory%2Fdevices%2Fmanage-stale-devices%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fsv-se%2Fazure%2Factive-directory%2Fdevices%2Fmanage-stale-devices%3C%2FA%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-480025%22%20slang%3D%22en-US%22%3ERe%3A%20Device%20-%20Removal%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-480025%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Guys%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethanks%20for%20the%20advise%20on%20the%20issues%20are%20they%20any%20other%20ways%20you%20know%20of%20bulk%20removing%20devices%20from%20azure%20i%20see%20i%20can%20remove%20it%20from%20intune%20via%20powershell%20or%20rule%20but%20are%20they%20anything%20for%20azure%20ad%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGrant%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-480068%22%20slang%3D%22en-US%22%3ERe%3A%20Device%20-%20Removal%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-480068%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F323263%22%20target%3D%22_blank%22%3E%40GrantBradley%3C%2FA%3E%26nbsp%3B%20Hi%20Grant%2C%20there%20are%20some%20cmdlets%20for%20removing%20from%20Azure%20AD-%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fmsonline%2Fremove-msoldevice%3Fview%3Dazureadps-1.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fmsonline%2Fremove-msoldevice%3Fview%3Dazureadps-1.0%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20that%20what%20you%20were%20thinking%20of%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-481038%22%20slang%3D%22en-US%22%3ERe%3A%20Device%20-%20Removal%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-481038%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%20Ethan%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ei%20am%20already%20aware%20of%20that%20currently%20it%20is%20handy%20for%20removing%20one%20device%20but%20i%20am%20looking%20to%20remove%20in%20bulk%20if%20that%20is%20possible%20as%20devices%20have%20built%20over%20time%20and%20had%20not%20been%20removed%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGrant%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F185103%22%20target%3D%22_blank%22%3E%40Ethan%20Stern%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-481055%22%20slang%3D%22en-US%22%3ERe%3A%20Device%20-%20Removal%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-481055%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F323263%22%20target%3D%22_blank%22%3E%40GrantBradley%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20could%20do%20something%20like%20this%20in%20PowerShell%20to%20delete%20stale%20devices%20from%20AAD%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24dt%20%3D%20%5Bdatetime%5D%E2%80%992018%2F12%2F12%E2%80%99%3C%2FP%3E%3CP%3EGet-MsolDevice%20-All%20-LogonTimeBefore%20%24dt%20%7C%20select-object%20-Property%20DeviceId%20%7C%20foreach%20%7B%24_.DeviceID%7D%20%7C%20foreach%20%7B%24_.Guid%7D%20%7C%20Remove-MsolDevice%20-Force%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20gets%20and%20deletes%20all%20devices%26nbsp%3B%3CSPAN%3Ewith%20a%20timestamp%20older%20than%20specific%20date.%20You%20can%20see%20more%20information%20in%20the%20doc%20I%20provided%20earlier.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
GrantBradley
New Contributor

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 

6 Replies

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

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 

@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?

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 

 

@Ethan Stern 

Hi @GrantBradley,

 

You could do something like this in PowerShell to delete stale devices from AAD:

 

$dt = [datetime]’2018/12/12’

Get-MsolDevice -All -LogonTimeBefore $dt | select-object -Property DeviceId | foreach {$_.DeviceID} | foreach {$_.Guid} | Remove-MsolDevice -Force

 

This gets and deletes all devices with a timestamp older than specific date. You can see more information in the doc I provided earlier.

Related Conversations
Extentions Synchronization
Deleted in Discussions on
3 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies