The script moves a user's SharePoint folder to another location within the same SharePoint site. To move 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.
Parameters:
- $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 source path of the folder.
- $newFolderPath - Specifies the destination path of the folder.
Note: You can use value references (e.g. %username%) to insert properties of the user account in the folder paths. 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.
PowerShell
$sharePointServer = "SharePointServer" # TODO: modify me
$webApplicationURL = "http://$sharePointServer/sites/MySite" # TODO: modify me
$folderPath = "Shared Documents/Folder A/%username%" # TODO: modify me
$newFolderPath = "Shared Documents/Folder B/%username%" # TODO: modify me
$session = New-PSSession $sharePointServer -Authentication Kerberos
$result = Invoke-Command -Session $session -ArgumentList $webApplicationURL, $folderPath, $newFolderPath -ScriptBlock {
param($webApplicationURL, $folderPath, $newFolderPath)
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
$site = New-Object Microsoft.SharePoint.SPSite("$webApplicationURL")
$web = $site.OpenWeb();
$folder = $web.GetFolder($folderPath)
if ($folder.Exists)
{
$folder.MoveTo($newFolderPath)
$folder.Update()
return "Folder moved successfully" # TODO: modify me
}
else
{
return "The source folder is missing" # TODO: modify me
}
}
Remove-PSSession -Session $session
$Context.LogMessage($result, "Information")