Quantcast
Channel: Exchange Server 2013 - Mobility and ActiveSync forum
Viewing all articles
Browse latest Browse all 1206

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

$
0
0

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




Viewing all articles
Browse latest Browse all 1206

Trending Articles



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