Change URL of SharePoint Library

It is possible to change the URL of a SharePoint Online Library via PowerShell. In this blog I tried to figure out if it would also be possible via a Power Automate flow.

Inspiration

This question from Socrates:

Is there any way to set the Internal Name of a document library on creation in a Send an HTTP Request action?

Power Users Community thread: HTTP Request Set Document Library Internal Name.

renamelibraryurl_test02

YouTube video

Before you continue reading. I also have a YouTube video about the setup.

Set-PnPList

Like mentioned in the introduction it is possible to update the URL of an existing document library in SharePoint Online. The PnP.PowerShell module has a Set-PnPList cmdlet.

One of the available parameters of this cmdlet is the -Path. You can actually use that to rename the library and change the URL, like in example 7.

Below would be a library URL change from Project Design Documents to PDD.

Definitely use that approach if you are more comfortable with PowerShell 😀

MoveTo

For the Power Automate approach I had a look in the code behind of the Set-PnPList cmdlet. I discovered there is a MoveTo method for the RootFolder.

This was also confirmed by the Change the URL of existing SharePoint List/Library[Tip] blog I found from Ivan Yankulov.

Flow setup

Make sure you test this properly before using the setup in a production environment.

renamelibraryurl

1. Add a Manually trigger a flow action.

renamelibraryurl_triggeraction

a. Add an input variable of type text, call it LibraryName
b. Add an input variable of type text, call it NewUrl

2. Add a Send an HTTP request to SharePoint action.
To retrieve the Id and Title of the document library.

renamelibraryurl_idandtitle

a. Select your preferred site in the Site Address
b. Use the GET method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

3. Add a second Send an HTTP request to SharePoint action.
This is to change the library URL, but also the Title is changed.

renamelibraryurl_moveto

a. Select your preferred site in the Site Address
b. Use the POST method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

4. Add a third Send an HTTP request to SharePoint action.
This is to change the library title back to the old value.

renamelibraryurl_renametitletoold

a. Select your preferred site in the Site Address
b. Use the POST method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

e. Use the Body from the code snippet below

That is it for the setup of this example.

Testing the flow

When you want to test it make sure you add a value for the Library Name and the NewUrl
renamelibraryurl_test01

That’s it, Happy testing!

You may also like...

2 Responses

  1. Andy says:

    This is AWESOME!
    Thank you so much. You are a genius!

  2. Tomáš Gerö says:

    Works great on first try.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.