Maintain control of your Microsoft 365 data
Post Reply
SWC
Novice
Posts: 5
Liked: never
Joined: Nov 10, 2017 12:27 am
Full Name: James Lemon
Contact:

Adding existing Team sites to Teams backup job vis PS

Post by SWC »

Hello All,

We are currently running veeam backup for ms 365 version 6.

Long story short, we are a company sitting in a 365 tenant with a bunch of other companies. What we are looking to do is backup only our particular users data not the entire tenant.

We have most other jobs under control via utilization of dynamic groups, so we basically say if user is a part of the group, then back them up. The only problem we have at the moment is Teams. Because the teams can be called stuff like "Water Sector", yes that's a real example of a team that belongs to us, we had to know a way to find everything that's ours.

So we wrote something that queries the dynamic 365 group we are already using above, and said give me a list of all teams created by anyone in the group, yay, so we have a CSV list of all teams that we own.

Now the next challenge, how to get that list of teams into our existing job, and update it.

This is where we have tried all manner of combinations (including getting chat GPT to write stuff) and haven't found something that works yet.

Below is the closest thing we have, but it's still very much broken:

Code: Select all

# Import the Veeam Backup for Microsoft Teams module
Import-Module Veeam.Archiver.PowerShell

# Retrieve the existing job by its name
$existingJob = Get-VBOJob -Name "SWC-Teams"

# Import the CSV file
$sites = Import-Csv -Path 'C:\temp\teams.csv'

# Iterate through each row in the CSV file
foreach ($site in $sites) {
    # Create a new Veeam Backup for Microsoft Teams site object
    $teamsSite = New-Object -TypeName Veeam.Archiver.Data.ObjectModel.Teams.TeamsSite -ArgumentList $site.Name, $site.Url

    # Create a new backup item for the Teams site
    $newItem = New-VBOBackupItem -TeamsSite $teamsSite.Site

    # Add the new backup item to the existing job
    Add-VBOBackupItem -Item $newItem -Job $existingJob
}
Anyone that's been able to do this yet? Our basic CSV file that holds the team names looks like:

"DisplayName"
"example123",
"example456",
"example789",
"example101112",

Cheers.
Mildur
Product Manager
Posts: 9848
Liked: 2610 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Adding existing Team sites to Teams backup job vis PS

Post by Mildur »

Hi James

The following sample adds a new Teams site to a backup job:

Code: Select all

$job = Get-VBOJob -Name "Organization Name"
$org = Get-VBOOrganization -Name "M365 Tenant"

$team = Get-VBOOrganizationTeam -Organization $org -DisplayName "Team Name"
$backupItemTeam = New-VBOBackupItem -Team $team -TeamsChats
Add-VBOBackupItem -Job $job -BackupItem $backupItemTeam
Your code should look like this (adding with teams chat):

Code: Select all

# Retrieve the existing job by its name
$org = Get-VBOOrganization -Name "Organization Name"
$existingJob = Get-VBOJob -Name "SWC-Teams"

# Import the CSV file
$sites = Import-Csv -Path 'C:\temp\teams.csv'

# Iterate through each row in the CSV file
foreach ($site in $sites) {
    $team = Get-VBOOrganizationTeam -Organization $org -DisplayName $site.Name
    $backupItemTeam = New-VBOBackupItem -Team $team -TeamsChats
    Add-VBOBackupItem -Job $existingJob -BackupItem $backupItemTeam
}
I didn't tested the code myself, please let me know if it works. If not, I run a test in my lab.

Source:
https://helpcenter.veeam.com/archive/vb ... pitem.html
https://helpcenter.veeam.com/archive/vb ... pitem.html

Best,
Fabian
Product Management Analyst @ Veeam Software
SWC
Novice
Posts: 5
Liked: never
Joined: Nov 10, 2017 12:27 am
Full Name: James Lemon
Contact:

Re: Adding existing Team sites to Teams backup job vis PS

Post by SWC »

OK update, so I have the example working and can add a single pre-existing team, I had to drop the -TeamChats option, seems like something they are doing at the tenant level to maybe stop that, not too concerned with chat at the moment so that's cool.

I then went back and tried the example you gave Fabian, and I get this:

Get-VBOOrganizationTeam : Cannot process argument because the value of argument "pattern" is null. Change the value of argument "pattern" to a non-null value.
At line:10 char:13
+ $team = Get-VBOOrganizationTeam -Organization $org -DisplayName $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-VBOOrganizationTeam], PSArgumentNullException
+ FullyQualifiedErrorId : ArgumentNull,Veeam.Archiver.PowerShell.Cmdlets.OrganizationItems.GetVBOOrganizationTeam
Mildur
Product Manager
Posts: 9848
Liked: 2610 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Adding existing Team sites to Teams backup job vis PS

Post by Mildur »

That message means, that $site.name was empty.
I just saw that the property in the csv is called displayname, and not name. Therefore we need to adjust my sample for that.

Code: Select all

# Retrieve the existing job by its name
$org = Get-VBOOrganization -Name "Organization Name"
$existingJob = Get-VBOJob -Name "SWC-Teams"

# Import the CSV file
$sites = Import-Csv -Path 'C:\temp\teams.csv'

# Iterate through each row in the CSV file
foreach ($site in $sites) {
    $team = Get-VBOOrganizationTeam -Organization $org -DisplayName $site.DisplayName
    $backupItemTeam = New-VBOBackupItem -Team $team -TeamsChats
    Add-VBOBackupItem -Job $existingJob -BackupItem $backupItemTeam
}
I had to drop the -TeamChats option, seems like something they are doing at the tenant level to maybe stop that, not too concerned with chat at the moment so that's cool.
If you want to protect Teams Chats, then it must be enabled first in M365 and on the Veeam Backup for Microsoft 365 server:
https://www.veeam.com/kb4322
https://www.veeam.com/kb4340

Best,
Fabian
Product Management Analyst @ Veeam Software
SWC
Novice
Posts: 5
Liked: never
Joined: Nov 10, 2017 12:27 am
Full Name: James Lemon
Contact:

Re: Adding existing Team sites to Teams backup job vis PS

Post by SWC »

Yep cool mate, literally just went back to the CSV file and found that myself just now, made sense once I thought about the error.

Appears to be all working now. Cheers and thank you!
Mildur
Product Manager
Posts: 9848
Liked: 2610 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Adding existing Team sites to Teams backup job vis PS

Post by Mildur »

You‘re welcome. :)
I‘m glad you found the issue and the script works now.

Best,
Fabian
Product Management Analyst @ Veeam Software
SWC
Novice
Posts: 5
Liked: never
Joined: Nov 10, 2017 12:27 am
Full Name: James Lemon
Contact:

Re: Adding existing Team sites to Teams backup job vis PS

Post by SWC »

Would you know of a way to speed up this process Fabian?

I have added logging to the PS script, and whilst everything is working OK, I'm averaging adding a single team every few minutes, and have thousands of teams to get through. It's looking like its going to take days still at this stage.

It seems like the poll back to 365 to find the team name might be causing it, I was thinking if I could find where the data is stored for the job, I might be able to just add all these teams sites without verification.

I'm doing a nightly pull of all teams based on dynamic groups, so theoretically if I added that data to the job each day without veeam verification, then it would be accurate.

Here is a snippet of the log showing the time it's taking:

[2023-06-07 10:51:27] Added team '123.
[2023-06-07 10:53:55] Added team '456.
[2023-06-07 10:56:20] Added team '789.
[2023-06-07 10:58:46] Added team '101112.
[2023-06-07 11:01:14] Added team '131415.
[2023-06-07 11:06:09] Added team '161718.

Cheers.
Mildur
Product Manager
Posts: 9848
Liked: 2610 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Adding existing Team sites to Teams backup job vis PS

Post by Mildur »

I assume, Get-VBOOrganizationTeam is where it will take a long time to get a list of all teams from M365.
In that case, I would try to get the output of Get-VBOOrganizationTeam for all teams to a new variable first. Please let me know if the script runs faster:

Code: Select all

# Retrieve mandatory informations
$org = Get-VBOOrganization -Name "Organization Name"
$existingJob = Get-VBOJob -Name "SWC-Teams"
$allteams = Get-VBOOrganizationTeam -Organization $org

# Import the CSV file
$sites = Import-Csv -Path 'C:\temp\teams.csv'

# Iterate through each row in the CSV file
foreach ($site in $sites) {
    $team = $allteams | where-object {$_.displayname -eq $site.DisplayName}
    $backupItemTeam = New-VBOBackupItem -Team $team -TeamsChats
    Add-VBOBackupItem -Job $existingJob -BackupItem $backupItemTeam
}
Best,
Fabian
Product Management Analyst @ Veeam Software
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 11 guests