kwizcom banner advertisement

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"
 
#Variables
$SiteURL="https://crescent.sharepoint.com"
$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)
    $Ctx.Load($Folder)
    $Ctx.ExecuteQuery()
    
    #Rename Folder
    $Folder.MoveTo($FolderNewURL)
    $Ctx.ExecuteQuery()

    Write-host -f Green "Folder has been renamed to new URL:"$FolderNewURL
}
Catch {
    write-host -f Red "Error Renaming Folder!" $_.Exception.Message
}
SharePoint Online: Rename Folder using PowerShell SharePoint Online: Rename Folder using PowerShell Reviewed by Salaudeen Rajack on December 19, 2016 Rating: 5

3 comments:

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

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

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.