Quantcast
Channel: Exchange Server 2013 - Administration, Monitoring, and Performance forum
Viewing all articles
Browse latest Browse all 1453

Help with Powershell script to delete old phonesync devices on Exchange 2013

$
0
0

Hi,

I'm trying to implement a PowerShell script that will remove any phonesync devices that haven't synced in 110 days. I'm new to PowerShell and saw a few examples on the web but can't get mine to work as needed. I need the script to also output all devices deleted to a time/date stamped CSV.

Here's my code, any help is appreciated.

Get-MobileDevice -result unlimited | Get-MobileDeviceStatistics | where {$_.LastSuccessSync -le (Get-Date).AddDays(“-110”)} | select identity, deviceid, lastsyncattempttime | Export-csv C:\PhoneSync\Logs\Stale_Devices_110days_$((Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')).csv | foreach (Remove-MobileDevice -Identity deviceid -confirm:$false)

My code is giving me this error:

The mobile device deviceid cannot be found.+ CategoryInfo          : NotSpecified: (:) [Remove-MobileDevice], ManagementObjectNotFoundException+ FullyQualifiedErrorId : [Server=WEBMAIL,RequestId=20842198-67a1-485c-b4d2-c8523be288fc,TimeStamp=1/18/2017 7:15:14 PM] [FailureCategory=Cmdlet
   -ManagementObjectNotFoundException] ABF1147C,Microsoft.Exchange.Management.Tasks.RemoveMobileDevice+ PSComputerName        : webmail.server.com

The CSV does export with the correct device(s).


Viewing all articles
Browse latest Browse all 1453

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>