Forum Discussion

msissues2552's avatar
msissues2552
Copper Contributor
Mar 20, 2023

Disabling mailbox in Exchange Online - VB.NET

Hello

I had used a code in the past - to disable AD accounts and mailboxes (VB.NET) for terminated users, that I used for years without a problem. Trying to set it up at my new job, however code doesn't work. Tried to connect in Powershell and test it there first - also not working.

Usually I created Runspace (using System.Management.Automation.Runspaces) and used Powershell command "Disable-Mailbox" to disable each mailbox. 

I can't even open Runspace - getting error "Connecting to remote server outlook.office365.com failed with the following error message: For more information, see the about_Remote_Troubleshooting Help topic." The account I run it under has remote powershell access.

If I try to use Connect-ExchangeOnline in Powershell itself (able to connect) and try to Disable Mailbox:

Disable-Mailbox -Identity "email address removed for privacy reasons"

 

- getting error "Write-ErrorMessage : ExE71684|Microsoft.Exchange.Configuration.ObjectModel.ProvisioningValidationException|The following error occurred during
validation in agent 'Archive ParameterSet Enforcement Agent': 'This operation only works with Archive or PermanentlyDisable parameters.'
At C:\Users\suxxxxx\AppData\Local\Temp\tmpEXO_o44bejfi.o2u\tmpEXO_o44bejfi.o2u.psm1:1121 char:13
+ Write-ErrorMessage $ErrorObject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [disable-Mailbox], ProvisioningValidationException
+ FullyQualifiedErrorId : [Server=DM6PR22MB2025,RequestId=58bba87a-90ea-3b76-852c-c15052cd3246,TimeStamp=Mon, 20 Mar 2023 20:32:02 GMT],Write-
ErrorMessage"

 

Why is this command no longer working? I don't want to permanently disable mailbox, as mailbox might be converted to shared or re-attached later.

 

Is removing license from mailbox only allowed now by using MsGraph? I'm using Powershell version 5.1 at the moment.

I appreciate your help!

  • It's been like this for a while. You don't disable mailboxes in Exchange Online, you remove the license (or Exchange plan) to deprovision the mailbox. The cmdlet complains that it cannot figure out what to do: you can only specify archive (to remove any enabled archive) or permanently remove an already soft-deleted mailbox and strip its attributes (ie unlicensed), so it won't get reattached when you reapply licenses within 30 days. Be advised that holds might also prevent you from disabling mailboxes.

    • msissues2552's avatar
      msissues2552
      Copper Contributor

      mderooij thank you. So how do I soft delete mailbox (which command)? Which command removes the license? 

      • mderooij's avatar
        mderooij
        MVP
        There is no command in EXO. What you can do is unlicense/remove the EXO plan through Graph, or when using Group-Based Licensing, you can remove the user from the group that provides the plan. Note that deprovisioning is not instant, so you might require a few checks (loop) when waiting for the deprovisioning to take place.

Resources