Apr 30 2024 05:04 AM
Hello
Please i need your help on this issue.
A couple of years ago, we setup a few Microsoft Teams (which had some files in the associated SharePoint sites). The vendor let the licensing lap, so the sites were deleted.
Unfortunately we could not restore the sites because it has pass the 93days default duration that Microsoft cloud stores data for deleted.
I would like to know how can we get new SPO sites re-created for the existing teams? Creating new teams isn't an option.
Is it possible as we want to get a new SPO sites recreated for the existing teams.
Apr 30 2024 06:13 AM
Hello @MikeJohn1710
If you're looking to recreate a SharePoint Online (SPO) site and connect it back to an existing Microsoft Team using PowerShell, you'll primarily be working with the Microsoft Teams PowerShell module and the SharePoint Online Management Shell. Below is a simplified example of how you might approach this task.
First, you'll need to install the Microsoft Teams PowerShell Module and SharePoint Online Management Shell if you haven't already.
Install-Module -Name PowerShellGet -Force -AllowClobber
Install-Module -Name MicrosoftTeams -Force
Install-Module -Name PnP.PowerShell -Force
You need to authenticate to both Microsoft Teams and SharePoint Online.
try {
# Connect to Microsoft Teams
$teamsCred = Get-Credential -Message "Enter your Microsoft Teams credentials"
Connect-MicrosoftTeams -Credential $teamsCred
# Connect to SharePoint Online
$spoCred = Get-Credential -Message "Enter your SharePoint Online credentials"
Connect-PnPOnline -Url "https://yourtenantname-admin.sharepoint.com" -Credentials $spoCred
} catch {
Write-Host "Failed to connect: $_" -ForegroundColor Red
exit
}
Create a new SharePoint site that you will later connect to the existing team.
# Define new site details
$siteUrl = "https://yourtenantname.sharepoint.com/sites/YourNewSiteName"
$siteTitle = "Your New Site Title"
$siteOwner = "email address removed for privacy reasons"
try {
New-PnPSite -Type TeamSite -Title $siteTitle -Alias "YourNewSiteName" -Owners $siteOwner -Url $siteUrl
Write-Host "Site created successfully at $siteUrl" -ForegroundColor Green
} catch {
Write-Host "Error creating site: $_" -ForegroundColor Red
exit
}
Retrieve the Team ID and link the newly created SharePoint site to this Team with error handling.
try {
# Retrieve the existing team by display name
$team = Get-Team -DisplayName "Your Existing Team Name"
if ($team -eq $null) {
Write-Host "Team not found." -ForegroundColor Red
exit
}
# Link the new SharePoint site to the team
Set-Team -GroupId $team.GroupId -SiteUrl $siteUrl
Write-Host "SharePoint site linked to Team successfully." -ForegroundColor Green
} catch {
Write-Host "Failed to link SharePoint site to Team: $_" -ForegroundColor Red
exit
}
Please ensure you have the necessary admin permissions in both Microsoft Teams and SharePoint Online.
Best regards,
Christian