Home

Quarantined Mobile Devices - Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-202831%22%20slang%3D%22en-US%22%3EQuarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-202831%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20Everyone%20--%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20put%20together%20a%20Powershell%20script%20to%20approve%20a%20device%20that%20has%20been%20quarantined.%26nbsp%3B%20By%20default%2C%20we%20quarantine%20everything%20and%20allow%20only%20what%20we%20want.%3C%2FP%3E%3CPRE%3E%24MobileDevice%20%3D%20Get-MobileDevice%20-Mailbox%20jdoe%20-Filter%20%7BDeviceAccessState%20-eq%20'Quarantined'%7D%3CBR%20%2F%3E%23%20allow%20the%20device%3CBR%20%2F%3ESet-CASMailbox%20-Identity%20jdoe%20-ActiveSyncAlloweDeviceIDs%20%24MobileDevice.DeviceId%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBy%20doing%20this%20-%20mail%20is%20now%20working%20on%20that%20mobile%20device%2C%20however%2C%20it%20still%20shows%20up%20in%20the%20list%20of%20quarantined%20devices.%26nbsp%3B%20%26nbsp%3BFurthermore%20-%20It%20is%20still%20returned%20as%20a%20quarntined%20device%20in%20the%20Get-MobileDevice%20cmdlet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsing%20powershell%20-%20how%20do%20you%20get%20it%20so%20it%20is%20no%20longer%20in%20the%20quarantined%20list%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3ESteve%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-202831%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-388851%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-388851%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F7987%22%20target%3D%22_blank%22%3E%40Stephen%20Bell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENearly%20perfect.%20A%20small%20typo%20on%20this%20line%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ESet-CASMailbox%20-Identity%20jdoe%20-ActiveSyncAlloweDeviceIDs%20%24MobileDevice.DeviceId%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThrows%20an%20error.%20This%20should%20work%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3ESet-CASMailbox%20-Identity%20jdoe%20-ActiveSyncAllowedDeviceIDs%20%24MobileDevice.DeviceId%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EQue%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-206623%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-206623%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20here%20is%20what%20I%20just%20found%20out%20--%20here%20is%20what%20I%20was%20running%2C%20and%20the%20device%20was%20still%20in%20the%20quarantined%20list.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24MobileDevice%20%3D%20Get-MobileDevice%20-Mailbox%20jdoe%20-Filter%20%7BDeviceAccessState%20-eq%20'Quarantined'%7D%3CBR%20%2F%3E%23%20allow%20the%20device%3CBR%20%2F%3ESet-CASMailbox%20-Identity%20jdoe%20-ActiveSyncAlloweDeviceIDs%20%24MobileDevice.DeviceId%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20then%20run%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24MobileDevice.DeviceAccessState%20%3D%20'Allowed'%3CBR%20%2F%3E%24MobileDevice.DeviceAccessStateReason%20%3D%20'Individual'%3C%2FPRE%3E%3CP%3EThe%20device%20is%20no%20longer%20shown%20in%20the%20mobile%20device%20list%20as%20quarantined.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-Steve%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-205358%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-205358%22%20slang%3D%22en-US%22%3E%3CP%3EStephen%2C%3C%2FP%3E%0A%3CP%3EThat's%20correct.%20Registered%20mobile%20devices%20for%20cloud%20mailbox%20users%20are%20not%20stored%20in%20an%20on-premises%20AD.%20The%20device%20information%20is%20stored%20in%20the%20Office%20365.%3C%2FP%3E%0A%3CP%3EIt%20seems%20to%20be%20a%20glitch%20in%20the%20UI%2C%20when%20mailbox%20access%20works%20for%20allowed%20device%20and%20the%20device%20still%20shows%20up%20as%20quarantined%20in%20the%20Admin%20Center.%3C%2FP%3E%0A%3CP%3E-%20Thomas%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-205318%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-205318%22%20slang%3D%22en-US%22%3E%3CP%3ETom%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20getting%20back.%26nbsp%3B%20Yes%20-%20it%20still%20is%20showing%20in%20the%20list%20of%20Quarantined%20devices.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20running%20Exchange%20Hybrid%20-%20100%25%20online.%26nbsp%3B%20I%20have%201%20server%20on%20prem%20for%20management.%26nbsp%3B%20Given%20that%2C%20mobile%20device%20information%20would%20not%20be%20stored%20in%20my%20on-prem%20AD%2C%20correct%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-Steve%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-205307%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-205307%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20device%20state%20is%20stored%20in%20an%20Active%20Directory%20attribute%20which%20needs%20to%20be%20replicated%20across%20all%20domain%20controllers%20until%20the%20state%20is%20properly%20returned%20when%20queried%20by%20a%20%3CEM%3EGet-MobileDevice%3C%2FEM%3E%20cmdlet.%3C%2FP%3E%0A%3CP%3EIs%20the%20device%20shown%20in%20the%20list%20of%20quarantined%20devices%20still%3F%20Even%20after%20some%20hours%20after%20the%20device%20has%20been%20allowed%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-205050%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-205050%22%20slang%3D%22en-US%22%3E%3CP%3EDefault%20Access%20Level%20%3D%20Quarantine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20moved%20to%20Exchange%20Online%20in%202016.%26nbsp%3B%20From%20day%201%2C%20we%20have%20had%20this%20policy%20-%20all%20mobile%20devices%20get%20Quarantined%20until%20approved%20by%20administrator.%26nbsp%3B%20All%20of%20the%20mobile%20devices%20that%20we%20have%20allowed%20have%20been%20allowed%20manually.%26nbsp%3B%20When%20we%20approve%20a%20device%20manaually%20(from%20the%20Mobile%20page)%20-%20the%20device%20is%20approved%20and%20removed%20from%20that%20list.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20just%20looking%20to%20do%20the%20same%20thing%20-%20but%20with%20Powershell.%26nbsp%3B%20Should%20involve%20less%20clicks%2C%20pages%2C%20and%20waiting%20for%20things%20to%20load.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20don't%20currently%20have%20any%20intune%20policies%20in%20place.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-204950%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-204950%22%20slang%3D%22en-US%22%3E%3CP%3EHave%20you%20checked%20the%20ActiveSyncOrganizationSettings%20for%20your%20tenant%20using%20Get-ActiveSyncOrganizationSettings%3F%3C%2FP%3E%3CP%3EWhat's%20the%20DefaultAccessLevel%3F%3C%2FP%3E%3CP%3EAre%20there%20any%20Intune%20policies%20in%20use%3F%3C%2FP%3E%3CP%3ECheers%2C%3CBR%20%2F%3EThomas%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-202949%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-202949%22%20slang%3D%22en-US%22%3EThank%20you%20-%20in%20this%20particular%20case%2C%20overriding%20was%20exactly%20what%20I%20was%20looking%20to%20do.%20I%20am%20still%20stuck%20as%20to%20why%20is%20shows%20up%20under%20my%20list%20of%20Quarantined%20Devices%20in%20the%20ECP%20portal.%20Any%20idea%20why%20that%20is%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-202940%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-202940%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20cmdlet%20you%20are%20using%20overrides%20the%20list%20of%20allowed%20devices%2C%20instead%20you%20should%20be%20adding%20to%20it%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESet-CASMailbox%20-Identity%20jdoe%20-ActiveSyncAlloweDeviceIDs%20%40%7Badd%3D%24MobileDevice.DeviceId%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-425883%22%20slang%3D%22en-US%22%3ERe%3A%20Quarantined%20Mobile%20Devices%20-%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-425883%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20were%20rolling%20out%20Android%20devices%20and%20wanted%20a%20way%20to%20allow%20all%20these%20whilst%20the%20roll%20out%20was%20happening.%26nbsp%3B%26nbsp%3B%20With%20help%20from%20this%20thread%20I%20wrote%20this%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24BlockedDevices%20%3D%20%40(Get-MobileDevice%20-Filter%20'DeviceAccessState%20-eq%20%22Blocked%22')%3CBR%20%2F%3E%24BlockedDevices.Foreach(%7B%3CBR%20%2F%3E%20%20%20%20Get-CASMailbox%20-Filter%20%22ActiveSyncBlockedDeviceIDs%20-eq%20%60'%24(%24_.DeviceId)%60'%22%20%7C%20Set-CASMailbox%20-ActiveSyncAllowedDeviceIDs%20%40%7Badd%3D%24(%24_.DeviceId)%7D%3CBR%20%2F%3E%7D)%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20would%20probably%20want%20to%20narrow%20down%20the%20Get-MobileDevice%20filter%20so%20BlockedDevices%20only%20contains%20the%20Devices%20you%20want%20allowing%20(DeviceModel%20for%20example%20if%20you%20are%20rolling%20out%20same%20hardware)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20ran%20it%20on%20a%20schedule%20during%20the%20rollout.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps%20someone%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Stephen Bell
Contributor

Hey Everyone --

 

I am trying to put together a Powershell script to approve a device that has been quarantined.  By default, we quarantine everything and allow only what we want.

$MobileDevice = Get-MobileDevice -Mailbox jdoe -Filter {DeviceAccessState -eq 'Quarantined'}
# allow the device
Set-CASMailbox -Identity jdoe -ActiveSyncAlloweDeviceIDs $MobileDevice.DeviceId

 

By doing this - mail is now working on that mobile device, however, it still shows up in the list of quarantined devices.   Furthermore - It is still returned as a quarntined device in the Get-MobileDevice cmdlet.

 

Using powershell - how do you get it so it is no longer in the quarantined list?

 

Thanks

Steve

10 Replies

The cmdlet you are using overrides the list of allowed devices, instead you should be adding to it:

 

Set-CASMailbox -Identity jdoe -ActiveSyncAlloweDeviceIDs @{add=$MobileDevice.DeviceId}

Thank you - in this particular case, overriding was exactly what I was looking to do. I am still stuck as to why is shows up under my list of Quarantined Devices in the ECP portal. Any idea why that is?

Have you checked the ActiveSyncOrganizationSettings for your tenant using Get-ActiveSyncOrganizationSettings?

What's the DefaultAccessLevel?

Are there any Intune policies in use?

Cheers,
Thomas

Default Access Level = Quarantine.

 

We moved to Exchange Online in 2016.  From day 1, we have had this policy - all mobile devices get Quarantined until approved by administrator.  All of the mobile devices that we have allowed have been allowed manually.  When we approve a device manaually (from the Mobile page) - the device is approved and removed from that list.  

 

I am just looking to do the same thing - but with Powershell.  Should involve less clicks, pages, and waiting for things to load.

 

We don't currently have any intune policies in place.  

The device state is stored in an Active Directory attribute which needs to be replicated across all domain controllers until the state is properly returned when queried by a Get-MobileDevice cmdlet.

Is the device shown in the list of quarantined devices still? Even after some hours after the device has been allowed?

Tom,

 

Thanks for getting back.  Yes - it still is showing in the list of Quarantined devices.  

 

I am running Exchange Hybrid - 100% online.  I have 1 server on prem for management.  Given that, mobile device information would not be stored in my on-prem AD, correct?

 

 

-Steve

Stephen,

That's correct. Registered mobile devices for cloud mailbox users are not stored in an on-premises AD. The device information is stored in the Office 365.

It seems to be a glitch in the UI, when mailbox access works for allowed device and the device still shows up as quarantined in the Admin Center.

- Thomas

So here is what I just found out -- here is what I was running, and the device was still in the quarantined list.

 

$MobileDevice = Get-MobileDevice -Mailbox jdoe -Filter {DeviceAccessState -eq 'Quarantined'}
# allow the device
Set-CASMailbox -Identity jdoe -ActiveSyncAlloweDeviceIDs $MobileDevice.DeviceId

 

If I then run:

 

$MobileDevice.DeviceAccessState = 'Allowed'
$MobileDevice.DeviceAccessStateReason = 'Individual'

The device is no longer shown in the mobile device list as quarantined.

 

-Steve

@Stephen Bell 

 

Nearly perfect. A small typo on this line:

 

Set-CASMailbox -Identity jdoe -ActiveSyncAlloweDeviceIDs $MobileDevice.DeviceId

 

Throws an error. This should work:

 

Set-CASMailbox -Identity jdoe -ActiveSyncAllowedDeviceIDs $MobileDevice.DeviceId

 

Que

 

We were rolling out Android devices and wanted a way to allow all these whilst the roll out was happening.   With help from this thread I wrote this;

 

 

$BlockedDevices = @(Get-MobileDevice -Filter 'DeviceAccessState -eq "Blocked"')
$BlockedDevices.Foreach({
Get-CASMailbox -Filter "ActiveSyncBlockedDeviceIDs -eq `'$($_.DeviceId)`'" | Set-CASMailbox -ActiveSyncAllowedDeviceIDs @{add=$($_.DeviceId)}
})

 

You would probably want to narrow down the Get-MobileDevice filter so BlockedDevices only contains the Devices you want allowing (DeviceModel for example if you are rolling out same hardware)

 

We ran it on a schedule during the rollout.

 

Hope this helps someone

Related Conversations
Spam Filtering too strong?
Tim Hunter in Security, Privacy & Compliance on
2 Replies
Quarantine Digest
Jerry Gonzalez in Microsoft 365 on
2 Replies
Quarantine Expiration Date
Tim Hunter in Security, Privacy & Compliance on
2 Replies