none
Remove all version from site and subsite RRS feed

  • Question

  • I want to remove all version of list/Library from site and its all subssite in sharepoint 2013.

    Is any powershell script to do that ?

    Any links to help this.

     

    Wednesday, April 19, 2017 6:58 AM

Answers

All replies

  • Here is the PowerShell scripts.

    $web = Get-SPWeb "http://yoursitename/"
    $list = $web.Lists["AC_TitleVersion"]
    $count =0;
    foreach ($item in $list.Items)
    {
        $itemTitle = $item["ID"];
        #$vtr = $item.Versions.Count;           
           # Write-Host "$itemTitle, has $vtr versions" -foregroundcolor Green;
            Write-Host "$itemTitle" -foregroundcolor Green;
      $item["VersionFlg"] = "true";
      $item.Update();
      $count=$count+1; 
    }
    Write-Host "Count :" $count;

    or
    go to list setting-> Set version setting ->"Create a version each time you edit an item in this list? " -> set Keep the following number of versions is 5. Earlier versions automatically deleted.

    ----------------------------------------------------------------------------

    Thanks

    Lalith

    ----------------------------------------

    Please mark as Answer, if this post solves your issue.


    Wednesday, April 19, 2017 1:03 PM
  • This will delete version from one list. I want to delete from all list/document library and subsite also.
    Wednesday, April 19, 2017 1:35 PM
  • Version is apply at list/ document lib levels. Version content is reside in the Web application content database. you have to loop all list or libs with sites and subsites.

    ----------------------------------------------------------------------------

    Thanks

    Lalith

    ----------------------------------------

    Please mark as Answer, if this post solves your issue.


    Wednesday, April 19, 2017 2:30 PM
  • Can you provide any code or link that would help.

    Thanks,


    • Edited by AkG25 Thursday, April 20, 2017 6:00 AM
    Thursday, April 20, 2017 5:59 AM
  • Use below code. Please compile at your end and do changes accordingly.

    foreach($WebApplication in $WebApplications){
        #Fetches site collections list within sharepoint webapplication
        Write-Output ""
        Write-Output "Working on web application $($WebApplication.Url)"
        $Sites = Get-SPSite -WebApplication $WebApplication -Limit All   

        foreach($Site in $Sites){
    $list = $web.Lists["AC_TitleVersion"]
     $count =0;
     foreach ($item in $list.Items)
     {
         $itemTitle = $item["ID"];
         #$vtr = $item.Versions.Count;           
            # Write-Host "$itemTitle, has $vtr versions" -foregroundcolor Green;
             Write-Host "$itemTitle" -foregroundcolor Green;
       $item["VersionFlg"] = "true";
       $item.Update();
       $count=$count+1; 
     }
     Write-Host "Count :" $count;
    }
    }

    ----------------------------------------------------------------------------

    Thanks

    Lalith

    ----------------------------------------

    Please mark as Answer, if this post solves your issue.


    Thursday, April 20, 2017 1:12 PM
  • Hi AkG25

    Please see the script from Delete all list Item versions from site and sub sites using CSOM and PowerShell  to see if it meets your requirements.

    Regards

    Reshmee


    • Marked as answer by AkG25 Tuesday, April 25, 2017 6:13 AM
    Thursday, April 20, 2017 3:23 PM
  • Hi,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, and we can learn from each other.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 25, 2017 5:20 AM