As documented by Veeam you need to remove user's data before you remove their account to actually free up a license. Veeam's documentation only shows how to do this one at a time which can be challenging if you accidentally backed up a lot of unnecessary accounts. Here is the script I came up with to do multiple accounts at a time.
Look at your backup job to see which repository it is using. The name is case sensitive and can be easier to copy paste from using the command "Get-VBORepository" and copy the repository name to "Repository Name"
Make sure you correct the path and name to your CSV file that has a list of email addresses or account names
In the variable $userEntry.name the .name is the ".name" is the name of your header. EG $userEntry.EmailAddress
If you do want to auto delete and not have to confirm each one add " -Confirm:$false" like so: "Remove-VBOEntityData -Repository $repository -User $user -Mailbox -ArchiveMailbox -OneDrive -Sites -Confirm:$false"
$repository = Get-VBORepository -Name "Repository Name"
$usersList = Import-Csv -Path "C:\temp\users.csv"
foreach ($userEntry in $usersList) {
$user = Get-VBOEntityData -Type User -Repository $repository -Name $userEntry.name
if ($user -ne $null) {
Remove-VBOEntityData -Repository $repository -User $user -Mailbox -ArchiveMailbox -OneDrive -Sites
Write-Host "Removed user: $($userEntry.Email)"
} else {
Write-Host "User not found: $($userEntry.Email)"
}
}
Once the user data is deleted you can then remove the user's license
$org = Get-VBOOrganization -Name "OrgName"
$usersList = Import-Csv -Path "C:\temp\users.csv"
foreach ($userEntry in $usersList) {
$licensedUser = Get-VBOLicensedUser -Organization $org -Name $userEntry.name
if ($licenseduser -ne $null) {
Remove-VBOLicensedUser -User $licensedUser
Write-Host "Removed user: $($userEntry.Email)"
} else {
Write-Host "User not found: $($userEntry.Email)"
}
}
If you have multiple repositories and want to scan for specific users accross all of them you can do so with the following script. Make sure you get a list of your repositories with the "Get-VBRRepository" command and fill in "Repository1", Repository2", etc.
$repositoryNames = @("Repository1", "Repository2", "Repository3")
$usersList = Import-Csv -Path "C:\temp\users.csv"
foreach ($repoName in $repositoryNames) {
$repository = Get-VBORepository -Name $repoName
if ($repository -ne $null) {
foreach ($userEntry in $usersList) {
$user = Get-VBOEntityData -Type User -Repository $repository -Name $userEntry.Email
if ($user -ne $null) {
Remove-VBOEntityData -Repository $repository -User $user -Mailbox -ArchiveMailbox -OneDrive -Sites -Confirm:$false
Write-Host "Removed user $($userEntry.Email) from repository $($repoName)"
} else {
Write-Host "User not found: $($userEntry.Email) in repository $($repoName)"
}
}
} else {
Write-Host "Repository not found: $($repoName)"
}
}