Remove Mobile Device: A positional parameter cannot be found that accepts argument 'False'.

Hi folks,

In Exchange 2013 Shell, I am trying to delete any old Mobile Devices that have not synced for 6 months or more. As a result, auditing require me to get the list of devices that are being deleted.

I wrote this script that I want to run once a month on a scheduled task. However, If I run manually and click accept to each device being deleted, it works fine. The moment I add the -Confirm $False to Remove-Mobile Device, I get an error:

"A positional parameter cannot be found that accepts argument 'False'."

Here is the script anyway but my question: has anyone managed to run an automated script that removes old active sync mobile devices?

$resultsarray = @()

$Devices = Get-MobileDevice -ResultSize Unlimited
ForEach ($Device in $Devices) {
  $ID  = $Device.Identity
  $DisplayName = $Device.UserDisplayName

  # Get the statistics for each Device
  $DeviceStats = Get-MobileDevice -Identity $ID | Get-MobileDeviceStatistics
 
  If ($DeviceStats.LastSuccessSync -le (Get-Date).AddMonths("-6"))
  {
 $DeviceType = $DeviceStats.DeviceType
 $State = $DeviceStats.DeviceAccessState
 $FirstSynced = $DeviceStats.FirstSyncTime
 $LastSynced = $DeviceStats.LastSuccessSync

 # Create a new object for the purpose of exporting as a CSV
 $pubObject = new-object PSObject
 $pubObject | add-member -membertype NoteProperty -name "Identity" -Value $ID
 $pubObject | add-member -membertype NoteProperty -name "Display Name" -Value $DisplayName
 $pubObject | add-member -membertype NoteProperty -name "Device Type" -Value $DeviceType
 $pubObject | add-member -membertype NoteProperty -name "Access State" -Value $State
 $pubObject | add-member -membertype NoteProperty -name "First Synced" -Value $FirstSynced
 $pubObject | add-member -membertype NoteProperty -name "Last Synced" -Value $LastSynced

 # Append this iteration of our for loop to our results array.
 $resultsarray += $pubObject
 
 # For the purpose of outputting to the screen if running the script manually
 Write-Host("Deleting device: $ID")
 Remove-MobileDevice -Identity $ID -Confirm $False
  }
}

$resultsarray | Export-Csv E:\DeletedMobileDevices.csv -NoTypeInformation

The error message that comes back in the shell says:

A positional parameter cannot be found that accepts argument 'True'.
    + CategoryInfo          : InvalidArgument: (:) [Remove-MobileDevice], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Remove-MobileDevice
    + PSComputerName        : ExchangeServerName.domain

Can anyone help with how you remove mobile devices without having to confirm their removal please?

Many thanks

Danny



  • Edited by Danny Webb Friday, May 15, 2015 10:18 AM .
May 15th, 2015 10:15am

Found the answer to all of those who are experiencing the same issue:

http://blogs.technet.com/b/messaging_with_communications/archive/2013/11/26/removing-activesync-devices-without-prompting.aspx

It appears it has to be written: -Confirm:$False

It will not accept any spaces in the command and it does require the :

I did not know that. Hopefully this helps others experiencing the same issue :)

Danny

  • Marked as answer by Danny Webb Friday, May 15, 2015 10:28 AM
Free Windows Admin Tool Kit Click here and download it now
May 15th, 2015 10:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics