How to remove a license from a user in Veeam Backup for Microsoft Office 365

Here is a hot topic for Veeam Backup for Microsoft Office 365 users: how to reallocate a license to a user without waiting 31 days. In order to remove a license from a user, you first need to delete that user’s data from all configured repositories and run the remove license command with PowerShell. This can be REALLY useful if you accidently backed up a user and no longer need to keep the data. Otherwise, you have to wait the 31-day threshold for the license to be reallocated. Seems simple enough, right? I found out very quickly that this could get complicated really quickly, especially when you have your users separated by components (like OneDrive and email) stored on different repositories. The configuration database saves users’ identifying information per repository, based on the component that was backed up to that repository. So, if the user’s email is sent to one repository and OneDrive sent to another, the script you would need to use to delete this data is different for each repository. I spent many hours with trial and error to figure out the right combinations and wrote this to save you the same headache.

Getting started

The following scripts and bonus tips can be used in any combination if that component is present on the repository for that specific user. Once you have queried the user by the right identifying attribute, you can then delete all data that the user has on the repository. Before we start deleting data, I would like to point out that this will not shrink the size of the database. Any data blocks for this user will be marked as white space and will be written over on the following job runs.

To start the process, you will need to open PowerShell from Veeam Backup for Microsoft Office 365. This will automatically load the required toolkit to run these commands.

Tip: If a command containing variables does not return a result, check your variables to make sure they return results. If the variable does not return a result, then something in the variable line is incorrect.

This next step will show you the user that is licensed and can be used later to see that the user is no longer licensed in the software:

#This will show that the user is licensed
#Fill in the domain name as it is shown in Veeam Office 365 

"DOMAIN.onmicrosoft.com" and the users email address "USER@DOMAIN.com"
$org = Get-VBOOrganization -Name "DOMAIN.onmicrosoft.com"
$User1 = Get-VBOLicensedUser -Organization $org -Name "USER@DOMAIN.com"
$User1

If you are not sure what data a user has on a repository, you can use the following:

#This script will show you what a data a user has on a particular repository
#Fill in "REPOSITORY" with the name of the repository as it is showing in Veeam Backup for Office 365 and the email address of the user you wish to remove the data for "USER@DOMAIN.com"

$repository = Get-VBORepository -Name "REPOSITORY" 
$user = Get-VBOEntityData -Type User -Repository $repository -Name "USER@DOMAIN.com" 
$user

Email

If the user has email existing on the repository, you will use the following section:

#This remove script is used for repositories containing users Email
#Fill in "REPOSITORY" with the name of the repository as it is showing in Veeam Backup for Office 365 and the email address of the user you wish to remove the data for "USER@DOMAIN.com"

$repository = Get-VBORepository -Name "REPOSITORY" 
$user = Get-VBOEntityData -Type User -Repository $repository -Name "USER@DOMAIN.com" 
Remove-VBOEntityData -Repository $repository -User $user -Mailbox -ArchiveMailbox -OneDrive -Sites
#Y will accept the deleting of data

SharePoint

The following scenario would be used in cases where the user does not have an email backup on the repository. The field to query the user is by Title and not Username email address. The title is generally the display name in the Office 365 environment, but you can find the title with the following script:

#This script is to show the displayed title field
#Fill in "REPOSITORY" with the name of the repository as it appears in Veeam Backup for Office 365

$Repository = Get-VBORepository -Name "REPOSITORY"
Get-VBOEntityData -Type site -Repository $Repository" | sort-object Title

If you have the title or are aware of what the title is, you can proceed with the following script, which will delete the data on the repository for you:

#This remove script is used for repositories containing users SharePoint
#Fill in "REPOSITORY" with the name of the repository as it appears in Veeam Backup for Office 365 and TITLE from the above query

$Repository = Get-VBORepository -Name "REPO"
$Site = Get-VBOEntityData -Type site -Repository $Repository -name "TITLE"
Remove-VBOEntityData -Repository $Repository -Site -OneDrive $Site
#Y will accept the deleting of data

OneDrive

This section is to be used if the repository does not contain email or SharePoint data. The script for users who have only OneDrive uses a combination of TITLE for the user-data attribute and User for the remove data attribute.

#This remove script is used for repositories containing users OneDrive
#Fill in "REPOSITORY" with the name of the repository as it appears in Veeam Backup for Office 365 and TITLE from the above query

$repository = Get-VBORepository -Name "REPOSITORY" 
$user = Get-VBOEntityData -Type User -Repository $repository -Name "TITLE" 
Remove-VBOEntityData -Repository $repository -User $user -OneDrive
#Y will accept the deleting of data

Remove license

Once you have removed the user’s data from all configured repositories, then you can remove the license for this user. The below script will pull the organization you have added into the console and desired user to then release the license. If you missed a repository, the error will tell you on what repository you still have remaining data:

#If there is no more data for this user on any repository you can use the following to remove the license
#Fill in the domain name as it is shown in Veeam Office 365 "DOMAIN.onmicrosoft.com" and the users email address "USER@DOMAIN.com"

$org = Get-VBOOrganization -Name "DOMAIN.onmicrosoft.com"
$licensedUser = Get-VBOLicensedUser -Organization $org -Name "USER@DOMAIN.com"
Remove-VBOLicensedUser -User $licensedUser

Conclusion

This process can be easy when you have an idea of which attributes to call. Hopefully, if you experience accidentally backing up a user and need to revoke their license, this will save you time in the future. If you do run into any problems along the way, we have an excellent community on the forums to help diagnose problems with any Veeam script.

Exit mobile version