We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Rename SharePoint folder

February 18, 2021 Views: 2950

The script renames a SharePoint folder of a user. To rename SharePoint folders in Adaxes, you can add the script to a business rule, custom command or scheduled task using the Run a program or PowerShell script action.


  • $sharePointServer - Specifies the NetBIOS name of the computer where the SharePoint Sever is homed.
  • $webApplicationURL - Specifies the URL of the SharePoint web application.
  • $sourceFolderPath - Specifies the path to the folder you want to rename.
  • $newFolderName - Specifies a new name for the fodler.
Note: You can use value references (e.g. %username%) to insert properties of the user account in the folder path and name. For example, if you specify the following path Shared Documents/Folder A/%username% and execute the script on a user whose username is jdoe, the resulting folder path will be Shared Documents/Folder A/jdoe.
Edit Remove
$sharePointServer = "SharepointServer" # TODO: modify me

$webApplicationURL = "http://$sharePointServer/sites/MySite" # TODO: modify me
$folderPath = "Shared Documents/%username%" # TODO: modify me
$newFolderName = "New Folder Name" # TODO: modify me

$session = New-PSSession $sharePointServer -Authentication Kerberos
$result = Invoke-Command -Session $session -ArgumentList $webApplicationURL, $folderPath, $newFolderName -ScriptBlock {
    param($webApplicationURL, $folderPath, $newFolderName)
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
    $site = New-Object Microsoft.SharePoint.SPSite("$webApplicationURL")
    $web = $site.OpenWeb();
    $folder = $web.GetFolder($folderPath)
        $folder.Item["Name"] = $newFolderName
        return "Folder renamed successfully" # TODO: modify me
        return "The specified folder does not exist" # TODO: modify me
Remove-PSSession -Session $session

$Context.LogMessage($result, "Information")
Comments 0
Leave a comment

Got questions?

Support Questions & Answers