Running the following script
$oldDevices = Get-MobileDevice -resultsize unlimited |
Get-MobileDeviceStatistics |
where {$_.LastSuccessSync -le (Get-Date).AddDays("-180")}
$OldDevices | foreach-object {
if ($Warn)
{
$null = $Warn.Message -match "Actual delayed:\s(?'Delay'[0-9]+)\s"
Start-Sleep -Milliseconds $Matches.Delay
$Warn = $null
}
Remove-MobileDevice ([string]$_.Guid) -confirm:$false -WarningVariable Warn
}
I don’t know What I am missing but I am getting the following result:
The operation couldn't be performed because 'USER\ExchangeActiveSyncDevices\REST§Outlook§7b723c9dbd7efbc1c4ded78588a7f9c6' matches multiple entries.
+ CategoryInfo : NotSpecified: (:) [Get-MobileDeviceStatistics], ManagementObjectAmbiguousException
+ FullyQualifiedErrorId : [Server=DM5PR1001MB2105,RequestId=58acfc5a-068a-489a-a2d5-3d559eae8295,TimeStamp=1/3/202
0 9:46:01 PM] [FailureCategory=Cmdlet-ManagementObjectAmbiguousException] 5B1053DA,Microsoft.Exchange.Management.T
asks.GetMobileDeviceStatistics
+ PSComputerName : outlook.office365.com