Thank you for asking this question on the **Microsoft Q&A Platform. **
It will be this script in PowerShell:
$dt = (Get-Date).AddDays(-120)
$Devices = Get-AzureADDevice -All:$true | Where {($_.ApproximateLastLogonTimeStamp -le $dt) -and ($_.AccountEnabled -eq $false)}
foreach ($Device in $Devices) {
Remove-AzureADDevice -ObjectId $Device.ObjectId
}
The following documentation has more details
Hope this helps,
Carlos Solís Salazar
----------
Accept Answer and Upvote, if any of the above helped, this thread can help others in the community looking for remediation for similar issues.
NOTE: To answer you as quickly as possible, please mention me in your reply.
That's great, thanks @Carlos Solís Salazar .
I assume the deletion can be reversed from the recycle bin supposed there is any device must be restored ?