Avatar of Roger Leech
Roger Leech
Flag for United States of America

asked on 

Need to delete mobile device access to 365 Mailboxes

I'm trying to write a simple PS script to remove EAS partnerships to a mailbox.  This only needs to be done 1 by 1, but Ideally I could import a CSV for it.  The CSV import I think I can do, but I'm having trouble with the 1 at a time script.  I'm really basic when it comes to PS so I'd appreciate any help - for each and variables are super confusing.  

This is what I have:  
$User = Read-Host -Prompt "Who's Mobile Devices are you going to nuke?  Enter username"
$Devices = Get-MobileDevice -Mailbox $user
ForEach ($Device in $Devices) 
    {
        Remove-MobileDevice $Device
     }
Clear-Variable User,Name,Devices

Open in new window

But I keep getting this:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "Persons Name\ExchangeActiveSyncDevices\iPad§Q5F3123456KHLAGK41P7VO" value of type 
"Deserialized.Microsoft.Exchange.Data.Directory.SystemConfiguration.MobileDevice" to type "Microsoft.Exchange.Configuration.Tasks.MobileDeviceIdParameter".
    + CategoryInfo          : InvalidData: (:) [Remove-MobileDevice], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-MobileDevice
    + PSComputerName        : outlook.office365.com

Open in new window


Then I'll do
Set-CASMailbox username -ActiveSyncDeviceIDs $null

Open in new window

as a finisher.  

What do you think of this process?  

Since I know you're curious, we just migrated to G-Suite and I want to prevent people from accidentally accessing their 365 mailbox on mobile.
PowershellMicrosoft 365Exchange

Avatar of undefined
Last Comment
Roger Leech

8/22/2022 - Mon