Script Repository

Delete SharePoint folder

October 14, 2015

The script deletes a user's SharePoint folder. To delete 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;
  • $folderPath - specifies the path to the folder you want to delete.
Note: You can use value references (e.g. %username%) to insert the properties of the user account in the folder path.
Edit Remove
$sharePointServer = "SharepointServer" # TODO: modify me

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

$session = New-PSSession $sharePointServer -Authentication Kerberos
$result = Invoke-Command -Session $session -ArgumentList $webApplicationURL, $folderPath -ScriptBlock {
    param($webApplicationURL, $folderPath)
    [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)
        return "Folder deleted" # TODO: modify me
        return "The specified folder does not exist" # TODO: modify me
Remove-PSSession -Session $session

$Context.LogMessage($result, "Information")

Comments ( 0 )
No results found.
Leave a comment