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
Here is the SharePoint Online PowerShell to rename a folder
#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: PnP PowerShell to Rename Folder
#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com/sites/marketing"
$FolderURL= "Shared Documents/Reports"
$FolderNewName ="Reports Archive"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Rename the Folder
Rename-PnPFolder -Folder $FolderURL -TargetFolderName $FolderNewName
SharePoint Online: Rename Folder using PowerShell SharePoint Online: Rename Folder using PowerShell Reviewed by Salaudeen Rajack on December 19, 2016 Rating: 5

5 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
  3. Hi i need block the rename of folder. Can you help me, say me how i make that?

    ReplyDelete
  4. Put the Library as read only then set permissions on the folder

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.