Wednesday, 27 August 2014

How to find and delete orphaned features in SharePoint using PowerShell

Use the following script to list all the features
   Get-SPFeature | ? { $_.Scope -eq $null }


Then use this script to delete the feature
    $feature = Get-SPFeature | ? { $_.DisplayName -eq "FeatureName" }
    $feature.Delete()

How to delete version history of SharePoint publishing pages in Powershell script.

$SPweb = Get-SPWeb "http://youSiteHere.com"
$versionsToKeep =5;
$SPlist = $SPweb.Lists["Tasks"]
 foreach ($SPitem in $SPlist.Items)
 {
   $currentVersionsCount= $SPItem.Versions.count
 
     if($currentVersionsCount -gt $versionstoKeep)
 {
 for($i=$currentVersionsCount-1; $i -gt $versionstoKeep; $i--)
  {
   $SPItem.versions[$i].delete()
  }
 }
 }

Tuesday, 12 August 2014

Update folder names using Power Shell in SharePoint

#Get the Web
$Web = Get-SPWeb "http://yourSharePointSite"

#New Name for the Folder
$NewFolderName = "PagesLibSubFolderNewName";

#Get the Folder to Rename by its path
$folder = $Web.GetFolder("http://yourSharePointSite/pages/CurrentFolderName");

if ($folder.Exists)
{
   #Set the New Name and Update
   $folder.Item["Name"] = $NewFolderName;
   $folder.Item.Update();
}