We help IT Professionals succeed at work.
Get Started

Need to delete mobile device access to 365 Mailboxes

Last Modified: 2020-01-14
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.
Watch Question
Enterprise Business Process Architect
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE