Vue normale

Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierFlux principal

Changing a SharePoint Site URL When Connected to Microsoft Teams

I shot myself in the foot today and I figured I’d share how I bandaged it back up. In actual fact, the healing was automagical.

We had a Microsoft Team with its usual backing SharePoint site, and we wanted to reclaim the URL from that SharePoint site. This isn’t an unusual occurrence when there isn’t much governance around Team or site creation. People create Teams with whatever names – and thus URLs – makes sense to them. Retrofitting some governance can take some renaming.

Changing a SharePoint site’s URL isn’t that hard these days. I changed the URL in the SharePoint Admin Center easily. See Change a site address – SharePoint in Microsoft 365 | Microsoft Docs for the steps.

Since we wanted to reuse the URL, the next step was to delete the redirect site which is left behind for the old URL PnP.Powershell. See my post Cleaning Up Redirect Sites in SharePoint Online for how and why you might want to do this.

After the deletion of the redirect site, we realized the team had been accessing the SharePoint site exclusively in Microsoft Teams, so we went to check that the files were still available in Teams. Uh-oh. No, they weren’t.

In Microsoft Teams, the Files tab in each channel was now broken, which is understandable – in retrospect. When we clicked into a Files tab, we got one of the standard “cute” error messages for a Document Library.

Panic ensued, at least on my end. I don’t like it when I break stuff.

I talked to my very smart colleagues at Sympraxis and we couldn’t come up with a reasonable fix for this. It was a good discussion, though, and showed the breadth of knowledge we have among us. I spent some time in Binglage, too, of course.

After a while, I was looking at the Files tabs again, and I noticed the in the General channel’s Files tab was working fine. Hmm. I tried another channel (this Team has 13 channels), and it was broken. I tried another Files tab – also broken. I went back to the first non-General Files tab, quite by accident, and it was working fine again.

Turns out, Teams was able to heal each Files tab by itself. By navigating to each of the Files tabs, navigating to another tab, and navigating back to the Files tab, Teams “fixed up” its connection to the corresponding folder in the SharePoint site’s Documents library. If I caught it right, on a few of the clicks into a Files tab, I saw the following message screen, showing that Teams was working on it.

I’m extremely relieved that Teams was able to self-heal in this situation. While I was incautious in my actions, Teams was smart enough to fix itself for me. This is a sign of the good stuff Microsoft is doing these days, realizing end users make mistakes, and so do people like me, even with a lot of experience.

Cleaning Up Redirect Sites in SharePoint Online

As our tenants evolve, we end up renaming sites and/or changing their URLs. When we change the URL of a site in the SharePoint Admin Center, the URL changes, just like we asked. SharePoint also leaves the old site in place, but converts it into a Redirect Site. So if we had a site at /sites/Procurement and we decide to change it to /sites/Purchasing (maybe due to a reorganization), people who have bookmarked the Procurement site will be redirected to the Purchasing site.

The Redirect Sites we end up with aren’t shown in the Active Sites listing. The only way we can figure out they are even there is to use PowerShell.

In most cases, we want that redirection to occur. But what about the cases where we mistakenly set up a site at the wrong URL? For example, maybe we create a site at /sites/HS by mistake, so we change it to /sites/HR. Later, we may have a new department called Highly Socialized. (Roll with it.) That /sites/HS URL is already “used up” by the Redirect Site. If we try to create a site with the /sites/HS URL, we’ll end up with /sites/HS2. SharePoint helpfully avoids a naming collision by adding the 2, and then a 3, then 4 – see if you can spot the pattern!

This becomes especially important if you’re creating sites with their URLs matching some sort of coding scheme. For example, for a property management company we work with, each Property has its own site with a URL using the Property Code. The property with a Property Code of 211 lives at /sites/211. By using that rigid connection to a property of the Property, we can guarantee unique URLs and keep them simple. Something like /sites/TheHilton-PhoenixEast just aren’t that fun to type!

If we mistakenly create the site for Property Code 211 at /sites/212 and then rename the URL to the correct /sites/211, we can get ourselves into trouble. What happens when we need to create a site for property 212? SharePoint will create the URL /sites/2122, which just isn’t right!

Therefore, we often want to clean out some of the Redirect Sites. Here’s the simple PowerShell to do this. Redirect Sites use the Site Template RedirectSite#0.

# Import modules
Import-Module PnP.PowerShell

$adminSiteUrl = "https://tenantName-admin.sharepoint.com"

Connect-PnPOnline -Url $adminSiteUrl -Interactive

$redirectSites = Get-PnPTenantSite -Template "RedirectSite#0"

########################################################################
# STOP HERE - Validate the redirect sites you actually want to remove. #
########################################################################

foreach ($site in $redirectSites) {
    Remove-PnPTenantSite -Url $site.Url -Force    
}

Note the big warning at line 10. Most likely, you won’t want to delete ALL the Redirect Sites. Once you’ve found them all, figure out what filter you might want to apply to $redirectSites before you run the foreach loop. Maybe you’ll do something like:

$redirectSites = Get-PnPTenantSite -Template "RedirectSite#0" | Where-Object { $_.Url -eq "https://tenantName.sharepoint.com/sites/212"

or

$redirectSites = Get-PnPTenantSite -Template "RedirectSite#0" | Where-Object { $_.Url -gt "https://tenantName.sharepoint.com/sites/211"

Good site hygiene is important, if only to protect your sanity. And use the URL renaming function thoughtfully. Don’t think of it as an easy way to clean up your mistakes, or your tenant may end up littered with Redirect Sites you don’t even know you have.

Resources

Manage site redirects – SharePoint in Microsoft 365 | Microsoft Docs

❌
❌