Maintain control of your Microsoft 365 data
Post Reply
Shagma
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 29, 2013 1:10 pm
Contact:

Delete oprhaned users

Post by Shagma »

I have deleted an organization from GUI. The data still remain in the database. How do I go about deleting all the data related to this organization?
I tried this, but it doesn't return anything:
Get-VBOEntityData -Type User -Repository $repository | Where {$_.Organization -like "orgiwanttodelete"}

If I do:
Get-VBOEntityData -Type User -Repository $repository
I can see a lot of users with the organization property I want to delete.

I don't understand why there isn't simply a "Do you want to delete this organizations data as well" option in the GUI when you delete organizations.
It is disrespectful of our time to not implement such low hanging fruit.
nielsengelen
Product Manager
Posts: 5796
Liked: 1215 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Delete oprhaned users

Post by nielsengelen »

You can remove data from a repository using Remove-VBOEntityData.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
Shagma
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 29, 2013 1:10 pm
Contact:

Re: Delete oprhaned users

Post by Shagma »

I know of the cmdlet. If you read my entire post, you can see that I don't understand how to apply the cmdlet. Hence my post.
nielsengelen
Product Manager
Posts: 5796
Liked: 1215 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Delete oprhaned users

Post by nielsengelen » 1 person likes this post

The following should do it:

Code: Select all

Import-Module "C:\Program Files\Veeam\Backup365\Veeam.Archiver.PowerShell\Veeam.Archiver.PowerShell.psd1"

$repo = Get-VBORepository -Name "Default Backup Repository" # Change this to match your repository
$org = Get-VBOEntityData -Type Organization -Repository $repo -Name "org" 

$usersList = Get-VBOEntityData -Type User -Repository $repo | Where-Object {$_.Organization -eq $org}
$groupsList = Get-VBOEntityData -Type Group -Repository $repo | Where-Object {$_.Organization -eq $org}
$sitesList = Get-VBOEntityData -Type Site -Repository $repo | Where-Object {$_.Organization -eq $org}

# Remove all users
foreach ($user in $usersList) {
    Write-Host "Removing user:" $user.DisplayName
	Remove-VBOEntityData -Repository $repo -User $user -Mailbox -ArchiveMailbox -OneDrive -Sites -Confirm:$false
}

# Remove all groups
foreach ($group in $groupsList) {
    Write-Host "Removing group:" $group.DisplayName
	Remove-VBOEntityData -Repository $repo -Group $group -Mailbox -ArchiveMailbox -OneDrive -Sites -GroupMailbox -GroupSite -Confirm:$false
}

# Remove all sites
foreach ($site in $sitesList) {
    Write-Host "Removing site:" $site.Title
	Remove-VBOEntityData -Repository $repo -Site $site -Confirm:$false
}
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
Shagma
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 29, 2013 1:10 pm
Contact:

Re: Delete oprhaned users

Post by Shagma »

Thanks, your script works. However there is something preventing deletion:
"Remove-VBOEntityData : Cannot start the job: Remove user: Consulting.Calendar. Error: Organization cannot be deleted. Please disable
all jobs pointing to it first."

I tried to look for the job by Get-VBOJob, but there is no job listed for this organization. How can I find this job which is pointing to the item I want to delete?
nielsengelen
Product Manager
Posts: 5796
Liked: 1215 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Delete oprhaned users

Post by nielsengelen »

That doesn't sound right. If you don't see any jobs at all with Get-VBOJob -Org "ORGANIZATION", I suggest you open a support case for insight as there may be something in the database that is causing this issue.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
kimsand520
Lurker
Posts: 2
Liked: never
Joined: Oct 15, 2020 9:41 am
Contact:

Re: Delete oprhaned users

Post by kimsand520 »

nielsengelen wrote: Sep 29, 2020 12:30 pm The following should do it:

Code: Select all

Import-Module "C:\Program Files\Veeam\Backup365\Veeam.Archiver.PowerShell\Veeam.Archiver.PowerShell.psd1"

$repo = Get-VBORepository -Name "Default Backup Repository" # Change this to match your repository
$org = Get-VBOEntityData -Type Organization -Repository $repo -Name "org" 

$usersList = Get-VBOEntityData -Type User -Repository $repo | Where-Object {$_.Organization -eq $org}
$groupsList = Get-VBOEntityData -Type Group -Repository $repo | Where-Object {$_.Organization -eq $org}
$sitesList = Get-VBOEntityData -Type Site -Repository $repo | Where-Object {$_.Organization -eq $org}

# Remove all users
foreach ($user in $usersList) {
    Write-Host "Removing user:" $user.DisplayName
	Remove-VBOEntityData -Repository $repo -User $user -Mailbox -ArchiveMailbox -OneDrive -Sites -Confirm:$false
}

# Remove all groups
foreach ($group in $groupsList) {
    Write-Host "Removing group:" $group.DisplayName
	Remove-VBOEntityData -Repository $repo -Group $group -Mailbox -ArchiveMailbox -OneDrive -Sites -GroupMailbox -GroupSite -Confirm:$false
}

# Remove all sites
foreach ($site in $sitesList) {
    Write-Host "Removing site:" $site.Title
	Remove-VBOEntityData -Repository $repo -Site $site -Confirm:$false
}
Im trying to get this one to work, but it does not set a $org variable.
I run: $org = Get-VBOEntityData -Type Organization -Repository $repo -Name "org"
If i then do "Write-host $org" it returns blank.
nielsengelen
Product Manager
Posts: 5796
Liked: 1215 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Delete oprhaned users

Post by nielsengelen »

And you changed "org" to your organization name?
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests