Maintain control of your Microsoft 365 data
Post Reply
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Hi all,

I have following question and need help:

How do i Backup all Sharepoint Sites but NOT Team Sites and Office Group Sites in Shareoint Online?
Is this possible?

Any help appreciated, i could not find any info regarding this.

Thanks a lot
Stephen
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

This is not directly possible via the GUI but I think it could be achieved using PowerShell and matching AzureAD/SP sites info with VBO.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

ok, i made this Script, but land up with Credential errors, cause VM-Backup is not Domain Joined. Is there a possible way to include the stored VeeamBackup Account i used in Veeam from my AAD tennant? Cause this is giving me a headache right now. Thanks for any help


Script Start
#>

$organizationname = "xxx.onmicrosoft.com"
$backupjob = "Testbackup"

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

$Org = Get-VBOOrganization -Name $organizationname
$Job = Get-VBOJob -Name $backupjob
$siteUrl = "https://xxx.sharepoint.com/sites/teams/"

$Sites = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Recurse -NotInJob

ForEach ($Site in $Sites) {
#Write-Progress -Activity "Parsing sites" -status "Site: $Sites.Name" -percentComplete ($i / $Sites.count * 100)
$newSite = New-VBOBackupItem -Site $Site
Add-VBOBackupItem -Job $Job -BackupItem $newSite
}

Write-Host "Added a total of " $Sites.count " sites to the job"

Script End


Powershell Output
PS C:\Scripts> .\VBO-ExcludeTeamsSharePointSites.ps1
Get-VBOOrganizationSite : The remote server returned an error: (401) Unauthorized.
At C:\Scripts\VBO-ExcludeTeamsSharePointSites.ps1:12 char:10
+ $Sites = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VBOOrganizationSite], FaultException
+ FullyQualifiedErrorId : System.ServiceModel.FaultException,Veeam.Archiver.PowerShell.Cmdlets.OrganizationItems.GetVBOOrganizationSite

Added a total of 0 sites to the job
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

Are you running the script on the VBO server? As I noticed you are getting a 401 Unauthorized message.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Yes its running on VBO Server. But i guess its a credential problem on Sharepoint, so i need to pass the credentials with the script for sharepoint, when it collects data, and i need to change the user when it wants to update the VBO Job on the server side. Tricky..wish i could just address the keyvault from VBO Server to handle all this
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

By default, it should be able to use the same user (administrator for eg) and work via PowerShell. A domain isn't needed. How did u add the organization to VBO (legacy auth or MFA)?
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

The organization is added with Modern with "allow for legacy auth" protocols
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

I just checked on the tennant for login errors from the vbo server, dont see any failed logins..., all are success
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Found out whats going on here and the problem: I want to collect all Sites after this URL https://xxx.sharepoint.com/teams/ to have them excluded in the JOB.
If i change this Line to $siteUrl = "https://xxx.sharepoint.com/teams/myteams" it works, but only for that specific site. But i need to collect all Team sites...
If i open up https://xxx.sharepoint.com/teams in a Browser, i get 404 not found

My script:

Import-Module "C:\Program Files\Veeam\Backup365\Veeam.Archiver.PowerShell\Veeam.Archiver.PowerShell.psd1"
$organizationname = "xxx.onmicrosoft.com"
$backupjob = "Skriptsharepoint"
$Org = Get-VBOOrganization -Name $organizationname
$Job = Get-VBOJob -Name $backupjob
$siteUrl = "https://xxx.sharepoint.com/teams"

$Sites = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Recurse -NotInJob

ForEach ($Site in $Sites) {
#Write-Progress -Activity "Parsing sites" -status "Site: $Sites.Name" -percentComplete ($i / $Sites.count * 100)
$newSite = New-VBOBackupItem -Site $Site
Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
}

Write-Host "Added a total of " $Sites.count " sites to the job"
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

First run the following command in a PowerShell cmd with administrator rights:

Code: Select all

Install-PackageProvider -Name NuGet -Force
Install-Module -Name PowerShellGet -Force
Install-Module -Name ExchangeOnlineManagement -RequiredVersion 1.0.1
Install-Module MicrosoftTeams
You have to do this only once normally to assure you can run the below script. It will request for your credentials twice but you could solve this by storing them in a $credential variable (unless you use MFA for the account).

Code: Select all

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

Connect-ExchangeOnline
Connect-MicrosoftTeams

$organizationname = "organization"
$backupjob = "backupjobwithoutTeams"
$Org = Get-VBOOrganization -Name $organizationname
$Job = Get-VBOJob -Name $backupjob

$Teams = (Get-Team |Select GroupId, DisplayName)

ForEach ($T in $Teams) {
   $siteUrl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL)
   Write-Host "URL for the" $T.DisplayName "team is" $siteUrl
}

$Sites = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Recurse -NotInJob

ForEach ($Site in $Sites) {
  #Write-Progress -Activity "Parsing sites" -status "Site: $Sites.Name" -percentComplete ($i / $Sites.count * 100)
  $newSite = New-VBOBackupItem -Site $Site
  Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
}

Write-Host "Added a total of " $Sites.count " sites to the job"
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Thanks, i am still working on it...having issues with this part here

$Teams = (Get-Team |Select GroupId, DisplayName)

ForEach ($T in $Teams) {$siteUrl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL)
Write-Host "URL for the" $T.DisplayName "team is" $siteUrl}
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

What is the issue? Are u receiving an error message or something else?
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Its the Get-Team command, i dont get anything out from the tennant, its just plain dead.
https://techcommunity.microsoft.com/t5/ ... -p/1576967

Module
Version Name Repository Description
------- ---- ---------- -----------
1.1.4 MicrosoftTeams PSGallery Microsoft Teams cmdlets module for Win...


Powershell
Get-Host | Select-Object Version

Version
-------
5.1.17763.1432
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

I'm not sure how to resolve the issue. It could be a permission issue with the used account. Another option is to use the Graph API however that requires you to create an application within Azure AD before you can benefit from it.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Changed to 1.1.5 MicrosoftTeams Preview, now i see something

Its a permission error on the Backup Account, tennant Admin works.


Get-Team : Error occurred while executing
Code: InvalidAuthenticationToken
Message: Access token validation failure. Invalid audience.
InnerError:
RequestId: 9126b03a-973d-440b-831b-8564705fcd2d
DateTimeStamp: 2020-09-10T08:47:30
HttpStatusCode: InvalidAuthenticationToken
At line:24 char:1
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Maybe you see the error? There is always just one Site added to Add-VBOExcludedBackupItem... i am getting dizzy at this point.



PS C:\Scripts> ForEach ($T in $Teams) {
$siteUrl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL)
Write-Host "URL for the" $T.DisplayName "team is" $siteUrl
}

Output
URL for the Test (Team) team is https://xxx.sharepoint.com/sites/TEAM-TEST
URL for the V-ID-CUS team is https://xxx.sharepoint.com/sites/V-ID-XXX
URL for the Webcenter Teams team is https://xxx.sharepoint.com/sites/Webcenter63
URL for the ZMI team is https://xxx.sharepoint.com/sites/W-WB-Med
URL for the Vernetzungstagung team is https://xxx.sharepoint.com/sites/Vernetzungstagung
and so on .....ok working

PS C:\Scripts> $Sites = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Recurse

PS C:\Scripts> ForEach ($Site in $Sites) {
$newSite = New-VBOBackupItem -Site $Site
Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
}

Write-Host "Added a total of " $Sites.count " sites to the job"
Added a total of 1 sites to the job





.................................................
My whole Script

$organizationname = "xxx.onmicrosoft.com"
$backupjob = "Skriptsharepoint"
$Org = Get-VBOOrganization -Name $organizationname
$Job = Get-VBOJob -Name $backupjob

# Credentials
$userName = "veeambackup@xxx.onmicrosoft.com"
$passwordText = Get-Content "C:\Scripts\Secure.txt"

# Convert to secure string
$securePwd = $passwordText | ConvertTo-SecureString

# Create credential object
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $securePwd

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

Connect-ExchangeOnline #-Credential $credObject
Connect-MicrosoftTeams #-Credential $credObject

$Teams = (Get-Team |Select GroupId, DisplayName)
#Test# Get-Team |Select GroupId, DisplayName | out-file -filepath C:\Scripts\teams_Dump.txt

ForEach ($T in $Teams) {
$siteUrl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL)
Write-Host "URL for the" $T.DisplayName "team is" $siteUrl
}

$Sites = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Recurse

ForEach ($Site in $Sites) {
$newSite = New-VBOBackupItem -Site $Site
Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
}

Write-Host "Added a total of " $Sites.count " sites to the job"
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

Right now, you have a foreach going over the teams and you set the $siteURL to a value. Once this is done you take it and put it in $Sites but since the foreach is done, it only will take the last value.

I believe the below should work:

Code: Select all

ForEach ($T in $Teams) {
  $siteUrl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL)
  Write-Host "URL for the" $T.DisplayName "team is" $siteUrl
  
  $Site = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Recurse
  $newSite = New-VBOBackupItem -Site $Site
  Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
}
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Thank you very much, i just tried it..., getting closer now, but is this line making trouble ? Write-Host "URL for the" $T.DisplayName "team is" $siteUrl

Here whats happening...

PS C:\Scripts> $Teams = (Get-Team |Select GroupId, DisplayName)

PS C:\Scripts> ForEach ($T in $Teams) {
$siteUrl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL)
Write-Host "URL for the" $T.DisplayName "team is" $siteUrl
$Site = Get-VBOOrganizationSite -Organization $org -URL $siteUrl -Recurse
$newSite = New-VBOBackupItem -Site $Site
Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
}

URL for the Test EWO team is https://xxx.sharepoint.com/sites/TestEWO
Add-VBOExcludedBackupItem : Cannot validate argument on parameter 'Job'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:6 char:34
+ Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Add-VBOExcludedBackupItem], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Archiver.PowerShell.Cmdlets.Jobs.AddVBOExcludedBackupItem

URL for the GMI Überarbeitung team is https://xxx.sharepoint.com/sites/GMIberarbeitung
Add-VBOExcludedBackupItem : Cannot validate argument on parameter 'Job'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:6 char:34
+ Add-VBOExcludedBackupItem -Job $Job -BackupItem $newSite
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Add-VBOExcludedBackupItem], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Archiver.PowerShell.Cmdlets.Jobs.AddVBOExcludedBackupItem
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen »

I only modified the part starting from the foreach to resolve it. You need to combine it with the upper part because you need to define $Job.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
dontlikemondays
Influencer
Posts: 16
Liked: never
Joined: Sep 01, 2020 7:52 am
Full Name: Stephen Künzle
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by dontlikemondays »

Had a typo error, that was the issue.
What a Journey its was to get here, its working for the Script part.
Great Support nielsengelen!
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Sharepoint Backup all Sites, but not Teams and Office Groups

Post by nielsengelen » 1 person likes this post

No problem. Glad it works for your needs. If you have any more questions or remarks, just let us know.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests