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.
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.
1. Add a Manually trigger a flow action.
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.
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.
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.
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
That’s it, Happy testing!
This is AWESOME!
Thank you so much. You are a genius!
Works great on first try.
Thank you! I made a couple attempts at PowerShell and then came across this info. I’ve used Power Automate to create 400k standardized folders for each new Job Number via HTTP Requests from our Portal. New Job triggers folder creation, all quote printing and downloads trigger another flow to automatically create a PDF of the quote via HTTP POST to the corresponding folder, etc. When a regional office is referenced by Dallas now rather than Coppell, TX simply changing the Document Library name may break some actions i.e. those that refer to the URL. I still want to be able to accomplish this via PowerShell or MS Graph API but this was a lifesaver. Much appreciated!