Monday, December 19, 2016

SharePoint Online: Rename Folder using PowerShell

Requirement: Rename a Folder in SharePoint Online.

sharepoint online rename folder using powershell

PowerShell to Rename Folder in SharePoint Online
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$FolderURL="/Project Documents/Active" #Relative URL
$FolderNewURL="/Project Documents/InActive"

Try {
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get the Folder
    $Folder = $Ctx.Web.GetFolderByServerRelativeUrl($FolderURL)
    #Rename Folder

    Write-host -f Green "Folder has been renamed to new URL:"$FolderNewURL
Catch {
    write-host -f Red "Error Renaming Folder!" $_.Exception.Message

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:


  1. It didnt work with relative url, i set the full url and it worked !
    Thanks for the script

  2. I have 25000 items list in online site, could you please tell me this script will work to delete list colunm.


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...