Thursday, August 30, 2012

Empty SharePoint Recycle Bins Programmatically with PowerShell

In a Database attachment method migration project, we decided to clear all the recycle bins to get some additional free space in databases. There were 3000+ site collections. Automation?

SharePoint Automation = PowerShell  :-)

Empty SharePoint Site Collection Recycle bin using PowerShell:
#Get the Site Collection
$Site = Get-SPSite "https://portal.crescent.com/sites/test"

#Delete all from 1st Stage Recycle bin
$Site.AllWebs | Foreach-object { $_.RecycleBin.MoveAllToSecondStage() }

#Empty 2nd Stage Recycle bin
$Site.RecycleBin.DeleteAll();

PowerShell Script to Empty SharePoint Recycle Bins Programmatically:
Lets empty the recycle bin of all site collection under a given web application using PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

$WebApp=Get-SPWebApplication "http://intranet.crescent.com"

    foreach ($SPSite in $webApp.Sites)
    {
      #get the collection of webs
      foreach($SPWeb in $SPSite.AllWebs)
         {
             #Empty the 1st Stage Recycle bin items PERMENANTLY
             #$SPWeb.RecycleBin.DeleteAll();
             
             #Send the 1st Stage Recycle bin items to 2nd Stage
             $SPWeb.RecycleBin.MoveAllToSecondStage();

              write-host "End-User Recycle Bin Items Deleted for:" 
              write-host $SPWeb.title ":" $SPWeb.URL "`n"

              #Dispose Web object
              $SPWeb.Dispose()
         }
             #Empty SharePoint site collection recycle bin (Second Stage Recycle bin) or Admin Recycle bin
             $SPSite.RecycleBin.DeleteAll();

             #Dispose Site object
             $SPSite.Dispose()

    write-host "Administrator Recycle bin Items Deleted for:" $SPSite.RootWeb.title "`n"
    }

Above code is fairly simple, and can be rewritten in C# also.


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 23, 2012

Create Shortcut in SharePoint Document Library

Requirement is to create a Shortcut link inside SharePoint document library. OK, Tried uploading the URL shortcut (.url) file, and got the error message saying "The following file(s) have been blocked by the administrator: URL Shortcut.url".

Solution: Add "Link to a Document" content type to the document library. Here is how to create shortcut in SharePoint document library:

Create Shortcut in SharePoint Document Library:
1. Go to Library Settings >> Advanced Settings.
shortcut in sharepoint document library
2. Enable "Allow management of content types" option and click OK
create shortcut in sharepoint library
3. In Library settings page, click on Content Types and click "Add from Existing Site content types" link.
create shortcut in sharepoint library
4. Choose "Link to a Document and click on "Add >" button, then OK.
create shortcut in sharepoint document library
5. Now create a New entry based on "Link to a Document", Enter the description & URL
sharepoint shortcut in document library
You are done!
sharepoint 2010 shortcut in document library
 
Drawback: The above method will not work when you move from HTTPS to HTTP and vice-versa.

Workaround: Create a simple HTML page with META REFRESH Tag and upload the html file to the document library.
<html>
<head>
<meta http-equiv="refresh" content="0;url=http://client.company.com/releases.cfm">
</head>
<body/>
</html>

Or you can create a HTML file with little JavaScript which send you to the target URL.
<html>
<head>
<script>
function loadFile()
{
document.location="http://client.company.com/releases.cfm";
}
</script>
</head>
<body onload="loadFile()">
</body>
</html>


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, August 21, 2012

Creating Dependent Features in SharePoint

In a recent project, had to create a feature which provisions bunch of Lists, Libraries and Pages with custom web parts. Those custom web parts also deployed as feature based solutions. So the requirement is: Activate the features which brings the custom web parts first, and then activate the feature which creates the pages with custom web parts.

Problem: If the user tries to activate the Main feature- which creates web part pages with custom web parts, with out activating a feature which brings the custom web part: Boom - Error!

Here comes the solution: Feature Activation dependency! How to Implement? Simple! just include the  <ActivationDependencies> in Feature.xm

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="2cec1d22-290f-41b2-a14b-164a82d43b04"
          Title="Crescent Project Site Template"
          Description="Feature for Crescent project site Template"
          Version="12.0.0.0"
          Hidden="FALSE"
          Scope="Web" >

<!--Set the activation dependency for Custom web parts feature -->
  <ActivationDependencies>
    <ActivationDependency FeatureId="GUID-OF-THE-DEPENDENT-FEATURE"/>
  </ActivationDependencies>
  
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
  </ElementManifests>
</Feature>

Important: If a dependent feature is Hidden, then it will be activated automatically when we activate the parent feature. If not, SharePoint will prompt the "Required Feature" page, instructing to activate the dependent feature first. We can't have <ActivationDependencies> In a Parent feature which has Hidden=TRUE attribute.
Dependent Features in SharePoint
Another frequent use of Feature Activation Dependency is: Page layouts!

Say, We've one Feature for Page Layouts and another for Custom content types. Custom Content types are the base for Page layouts (In another words, Page layout fields are from Custom content type). So we need Feature Activation Dependency here as well.

Further MSDN Readings:
http://msdn.microsoft.com/en-us/library/ee231535.aspx
http://msdn.microsoft.com/en-us/library/ms472474%28v=office.12%29.aspx


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 16, 2012

Install Features Programmatically in SharePoint

Generally, we use STSADM command line to Install features by STSADM –o installfeature –name FeatureName. or Install-SPFeature PowerShell Cmdlet. At times, we may have to execute stsadm programmatically to install a Feature. Say for e.g. from console applications or from another feature activation code.  Here is how it can be achieved.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Diagnostics;

namespace InstallFeature
{
    class Program
    {
        static void Main(string[] args)
        {
            string site;
            if (args.Length == 0)
            {
                Console.WriteLine("Enter the Web Application URL:");
                site = Console.ReadLine();
            }
            else
            {
                site = args[0];
            }
            SPSite tmpRoot = new SPSite(site);

           //Get the particular Feature, if installed already
            SPFarm farm = tmpRoot.WebApplication.Farm;
            SPFeatureDefinitionCollection features = farm.FeatureDefinitions;
            SPFeatureDefinition feature = features[new Guid("05BA4E54-C1E9-4244-8276-06451EBBB260")];


            if (feature == null)    //Feature is not installed!
            {
                // install the feature
                Process oProcess = new Process();
                ProcessStartInfo oProcInfo = new ProcessStartInfo();


                // Get the STSADM command's path
                string commonFilesPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonProgramFiles);
                oProcInfo.FileName = commonFilesPath + @"\Microsoft Shared\web server extensions\12\BIN\" + "stsadm.exe ";

                oProcInfo.Arguments = " -o installfeature -name Crescent.Support.Link -force";
                oProcInfo.WindowStyle = ProcessWindowStyle.Hidden; 
                oProcInfo.UseShellExecute = true;

                oProcess.StartInfo = oProcInfo;
                //execute the stsadm command.

                oProcess.Start();
                oProcess.WaitForExit();
            }
        }
    }
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, August 12, 2012

How to Create Site Columns Programmatically in SharePoint

Requirement: Add Site columns to the SharePoint site programmatically as part of a site provisioning code.

Code to Add a New Site column to SharePoint Site:
 
 using (SPSite site = new SPSite("http://sharepoint.com"))
            {
               SPWeb web = site.RootWeb;
               
                //Add Site Column

               //Add choice Field "Operating Country"
               if (!web.Fields.ContainsField("Operating Country"))
               {
                  string countryField=web.Fields.Add("Operating Country", SPFieldType.Choice , false);

                   //Set the Field Properties
                   SPFieldChoice OperatingCountry = (SPFieldChoice)web.Fields.GetField("Operating Country");
                   
                   //Set the group for the Site column
                   OperatingCountry.Group = "Crescent";
                   
                   //Add the choices
                   string[] countries = new string[] { "Germany", "Japan", "Romania", "Switzerland", "United States" };
                   OperatingCountry.Choices.AddRange(countries);
                   
                   //Set the default value
                   OperatingCountry.DefaultValue = "United States";

                   //Set Fillable value
                   OperatingCountry.FillInChoice = true;

                   //Update the field
                   OperatingCountry.Update();

               }
            }

Alternate Approach: 
Create SharePoint site column programmatically with C# Object Model code:
  
namespace CreateSiteColumns
{
    class Program
    {
        static void Main(string[] args)
        {
           using (SPSite oSPSite = new SPSite("http://SharePoint.com"))
            {
                using (SPWeb oSPWeb = oSPSite.RootWeb)
                {
                    //Method 1
                    oSPWeb.Fields.Add("bptSalary1", SPFieldType.Currency, true);
                    oSPWeb.Update();

                    //Method 2
                    string SalaryField2 = oSPWeb.Fields.Add("bpt-Salary2", SPFieldType.Currency, false);

                   //Set the Properties
                    SPFieldCurrency bptSalary2 = (SPFieldCurrency)oSPWeb.Fields.GetFieldByInternalName(SalaryField2);

                    bptSalary2.Group = "BPT Site columns";
                    bptSalary2.DisplayFormat = SPNumberFormatTypes.TwoDecimals;
                    bptSalary2.MinimumValue = 0;
                    bptSalary2.Update();

                    //Method 3 using Field schema
                    string bptSalary3 = "<Field Type=\"Number\" DisplayName=\"Bpt-InvoiceNum\" Required=\"TRUE\" EnforceUniqueValues=\"FALSE\" Indexed=\"FALSE\" Min=\"1\" Max=\"10000\" Group=\"Bpt Columns\" ID=\"{b81c7da6-1317-46fa-a32b-9f446c30b6e9}\" SourceID=\"{03548e22-e4b5-4ae0-b325-12c584754e72}\" StaticName=\"Bpt-InvoiceNo\" Name=\"Bpt-InvoiceNo\"></Field>";

                    // Call the SharePoint method to create the field.
                    oSPWeb.Fields.AddFieldAsXml(bptSalary3);
                    oSPWeb.Update();
                }
            }
        }
    }
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, August 10, 2012

Deploy Custom List templates(.stp) as Feature based Solution in SharePoint

Requirement: Had a custom List template, and wanted to make it available in create page of all sites of the site collection.

Solution:  How to deploy SharePoint list template? Create a WSP builder solution to deploy the .stp file to the List template gallery of required site collections! Just create a Feature with the below element.xml file. Add the .Stp file to the solution.

Here is Elements.xml file:
 <?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="EnrollmentTemplate" List="114" Url="_catalogs/lt" RootWebOnly="TRUE">
    <File Url="Enrollment.stp" Type="GhostableInLibrary">
      <Property Name="LanguageDisplay" Value="English" />
      <Property Name="Version" Value="3" />
    </File>
  </Module>
 </Elements>

Project Structure:
SharePoint 2007 Project to Deploy List Templates (.stp)

Same way, Custom Site templates also packed.Just Change the line in element.xml as:
<Module Name="EnrollmentSiteTemplate" List="116" Url="_catalogs/wt" RootWebOnly="TRUE">



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, August 4, 2012

Delete Attachments from SharePoint List Items using Powershell

There is a requirement to delete all the attachments named as "xyx.presales.document.docs" from a SharePoint List where 100's of list items already created with lot of attachments. 

This requirement can be achieved with either SharePoint Object model or with PowerShell. Here is the script to programmatically delete the attachments based on its name.

$web=Get-SPWeb -identity "http://sharepointsite.com"
$list=$web.lists["Documents"];
foreach($item in $List.Items)
  {
        for($i=$item.Attachments.count-1; $i -ge 0; $i--) 
        { 
             if($item.Attachments[$i].endswith("presales.document.docx"))
             {
            write-host "File Deleted:" $item.Attachments[$i]
               $Item.Attachments.Delete($item.Attachments[$i])
              }
            
        }  
           $item.update()
  }


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Add Web Parts to the Page Programmatically

Requirement is to add OOTB and Custom web parts to a web part page programmatically via features. I'm sharing the code snippets:

To Add Out Of The Box Web Parts: (E.g. Content Query Web Part, Content Editor, Page Viewer Web Part, etc):
      
                SPWeb web = properties.Feature.Parent as SPWeb;   
                //Create the SPLimitedWebPart Manager to Add web parts
                SPLimitedWebPartManager WebPartMgr = web.GetLimitedWebPartManager("Home.aspx", PersonalizationScope.Shared);
               
                //Add Project Matter Title CEWP
                ContentEditorWebPart ProjectDetailsTitleCEWP = new ContentEditorWebPart();

                //Set the Properties of the CEWP
                ProjectDetailsTitleCEWP.Title = "Project Matters Title";
                ProjectDetailsTitleCEWP.ChromeType = PartChromeType.None;

                //Create an XmlElement to hold the value of the Content property.
                XmlElement ProjectDetailsTitle = new XmlDocument().CreateElement("content");
                ProjectDetailsTitle.InnerText = "<img style='BORDER: 0px' src='/_layouts/images/crescent/Project-details.jpg' align='middle'><span style='color: black; font-size: medium; vertical-align: middle'>Project</span><span style='COLOR: #971a1e; font-size: medium; vertical-align: middle'>Details</span><hr style='color: navy;' size='1' />";
                ProjectDetailsTitleCEWP.Content = ProjectDetailsTitle;

                //Add the CEWP to BODY zone
                WebPartMgr.AddWebPart(ProjectDetailsTitleCEWP, "Body", 1);
                WebPartMgr.SaveChanges(ProjectDetailsTitleCEWP);

Add Page Viewer web part
      
                 PageViewerWebPart pvwp = new PageViewerWebPart(); 
                 pvwp.Title = "Project Accounting";
                 pvwp.ChromeType = PartChromeType.None;
                 pvwp.ID = "PageViewer";
                 pvwp.Height = "600px";
                 pvwp.ContentLink = "http://www.Crescent.com/Projects.com";
                 ProjectAccountingWebPartMgr.AddWebPart(pvwp, "Body", 0);
                 ProjectAccountingWebPartMgr.SaveChanges(pvwp);

Programmatically add ListView webpart from: "Project Documents" library
              
                //Get the object of the list of which we are creatin the list viewer webpart
                SPList ProjectDocList = web.Lists["Project Documents"];
                ListViewWebPart oProjectDocsListViewWP = new ListViewWebPart();
                //Set the properties of the webpart
                oProjectDocsListViewWP.ChromeType = PartChromeType.None;
                oProjectDocsListViewWP.Title = "Project Documents";
                oProjectDocsListViewWP.ListName = ProjectDocList.ID.ToString("B").ToUpper();
                oProjectDocsListViewWP.ViewGuid = ProjectDocList.DefaultView.ID.ToString("B").ToUpper();
 
                //Define the zone in which webparts need to be added
                WebPartMgr.AddWebPart(oProjectDocsListViewWP, "Left", 3);
 


Add custom web part programmatically:
In order to add custom web parts, we need to get the web parts from web part gallery first. Here is the helper method:

     //Method to Get the custom web part
        public static System.Web.UI.WebControls.WebParts.WebPart GetWebPart(SPWeb web, string webPartName)
        {
            var query = new SPQuery();
            query.Query = String.Format(
                "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>{0}</Value></Eq></Where>",
                webPartName);

            SPList webPartGallery;
            if (web.IsRootWeb)
            {
                webPartGallery = web.GetCatalog(
                   SPListTemplateType.WebPartCatalog);
            }
            else
            {
                webPartGallery = web.ParentWeb.GetCatalog(
                   SPListTemplateType.WebPartCatalog);
            }
            var webParts = webPartGallery.GetItems(query);
            var typeName = webParts[0].GetFormattedValue("WebPartTypeName");
            var assemblyName = webParts[0].GetFormattedValue("WebPartAssembly");
            var webPartHandle = Activator.CreateInstance(
                assemblyName, typeName);

            System.Web.UI.WebControls.WebParts.WebPart webPart =
                (System.Web.UI.WebControls.WebParts.WebPart)webPartHandle.Unwrap();
            return webPart;
        }

Here is how we can add Custom Web Parts to a page:
   //Add "Project Search" Custom web part
                  SPWeb web = properties.Feature.Parent as SPWeb;   

  //Create the SPLimitedWebPart Manager to Add web parts
                SPLimitedWebPartManager WebPartMgr = web.GetLimitedWebPartManager("Home.aspx", PersonalizationScope.Shared);

  //Get the Web Part from Web Part Gallery
                using (System.Web.UI.WebControls.WebParts.WebPart ProjectSearchWp = GetWebPart(web, "ProjectSearch.webpart"))
                {
      //Set the web part Properties
                    ProjectSearchWp.ChromeType = PartChromeType.None;
                    ProjectSearchWp.Title = "Project Search Web Part";
      //Add the web part to Left zone 
                    WebPartMgr.AddWebPart(ProjectSearchWp, "Left", 1);
                    WebPartMgr.SaveChanges(ProjectSearchWp);
                }  



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, August 3, 2012

SharePoint List Registration IDs Reference

Reference Table for SharePoint List Registration ID:


ID
Name
100 Generic list
101 Document library
102 Survey
103 Links list
104 Announcements list
105 Contacts list
106 Events list
107 Tasks list
108 Discussion board
109 Picture library
110 Data sources
111 Site template gallery
112 User Information list
113 Web Part gallery
114 List template gallery
115 XML Form library
116 Master pages gallery
117 No-Code Workflows
118 Custom Workflow Process
119 Wiki Page library
120 Custom grid for a list
130 Data Connection library
140 Workflow History
150 Gantt Tasks list
200 Meeting Series list
201 Meeting Agenda list
202 Meeting Attendees list
204 Meeting Decisions list
207 Meeting Objectives list
210 Meeting text box
211 Meeting Things To Bring list
212 Meeting Workspace Pages list
300 Portal Sites list
301 Blog Posts list
302 Blog Comments list
303 Blog Categories list
1100 Issue tracking
1200 Administrator tasks list
2002 Personal document library
2003 Private document library

You can get the List IDs by Enumeration SPListTemplateType. MSDN Reference: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, August 2, 2012

Event Receivers vs Workflows - Decide Which One to Use

As SharePoint Event Receivers & SharePoint workflows have a lot of similarities, Many people stuck on deciding which one to go with: Event Receiver or Workflow? event receiver vs. workflow in SharePoint is always tricky to decide.

Main Differences Between SharePoint Event Receivers and SharePoint Workflows are:

1. Event handlers Can't be manually initiated - workflows can be initiated either automatically or manually.

2. Event Handlers can be Synchronous or Asynchronous - Workflows are always async (They executes after the operation)

3. In Event Receivers we can cancel the operation (such as add/update/delete) - But in Workflows its not possible.

4. Event handlers execute from a Particular WFE, So when some thing goes wrong in that WFE, It may end-up. But Workflow Jobs are robust and  can resume even after Reboots.

5. Usually Event handlers runs for short period - Workflows can be longer even for years!

6. There is no User Interface/user Interaction in Event Receivers - Workflows can have user interactions such as getting user input in Initiation forms.

7. As the Name indicates, SharePoint Event receivers are triggered by events like New Item Adding-Added, Updating-Updated, Deleting-Deleted, etc. - But Workflows triggered only on Creation/Change/deletion.

8. Event Receivers are created using Visual studio - Workflows can be via SharePoint user interface, SharePoint Designer, Visio or Visual studio.

9. Workflows leaves "Workflow History" logs which we can refer for debugging - Event handler doesn't do such.

10. Event receivers are better for large volume - Workflows are better for small amount of data.

This one from Codeplex: SharePoint 2010 event receiver vs workflow
event receiver vs workflow

[Click on the picture to Enlarge]
Thanks to: https://spdevguide.codeplex.com

MSDN version: http://msdn.microsoft.com/en-us/library/ff649084.aspx
sharepoint 2010 event receiver vs workflow



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, August 1, 2012

Get SharePoint Recycle Bin Storage Size

In a Database attachment method migration project, wanted to get the insights on how much space being occupied by SharePoint Admin Recycle bin for all site collections. There were 3000+ site collections.

PowerShell Script to get First Stage recycle bin size:
function global:Get-SPSite($url) {
    return new-Object Microsoft.SharePoint.SPSite($url)
 } 
 
function Get-RecyclebinSize($SiteURL)
{   
    #Get the site collection
    $site = Get-SPSite $SiteURL
     
    # Create SPRecycleBinQuery object to Query Reycle bin
    $SPRecycleBinQuery = New-Object -TypeName Microsoft.SharePoint.SPRecycleBinQuery
    $SPRecycleBinQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::FirstStageRecycleBin
    
    # Set the query should return maximum number of objects 
    $SPRecycleBinQuery.RowLimit = [int]::MaxValue-1
    
    # Get the sum of values of the 'Size' property of all Recycle Bin items and assign it to a variable
    $RecycleBinSize = $site.GetRecycleBinItems($SPRecycleBinQuery) | Measure-Object -Property Size -Sum | Select-Object -ExpandProperty Sum
    
    # Calculate the value in Mbs and returned the rounded value to the caller       
    return ([System.Math]::Round(($RecycleBinSize/1Mb),2))
}

 $Size = Get-RecyclebinSize "https://intranet.crescent.com/sites/sales"
 write-host "First Stage Recycle bin Size (in MB):" $size 

Here is the PowerShell script to get the 2nd stage recycle bin's size in SharePoint 2010:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

$WebApp=get-spwebapplication "http://sharepoint.crescent.com"

    foreach ($SPSite in $WebApp.Sites)
    {       
     # SPRecycleBinQuery to Query Reycle bin    
     $SPRecycleBinQuery=new-object Microsoft.SharePoint.SPRecycleBinQuery
     $SPRecycleBinQuery.OrderBy = [Microsoft.SharePoint.SPRecycleBinOrderBy]::DeletedDate;
     $SPRecycleBinQuery.IsAscending = $false;
     $SPRecycleBinQuery.RowLimit = 2000
     $SPRecycleBinQuery.ItemState = [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin
   
     $SPRecycleBinItemCollection  = $SPSite.GetRecycleBinItems($SPRecycleBinQuery)
     
       $Size=0
       
        for ($i=$SPRecycleBinItemCollection.Count-1; $i -GE 0;  $i--)
            {
                        $guid = $SPRecycleBinItemCollection[$i].ID;
                        #$SPRecycleBinItemCollection.Restore($guid);
                        #$SPRecycleBinItemCollection.Delete($guid);
                        $Size+=$SPRecycleBinItemCollection[$i].Size
                    
            }
          write-host "Recycle bin Size in" $SPSite.RootWeb.Title "-"  $SPSite.RootWeb.URL ":" ($size/1MB)   
       }


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...