Top Menu

Friday, March 29, 2013

PowerShell - List Data Migration

Scenario:
I had to migrate data from ListA to ListB with the condition that values in Created By, Create Date, Updated By and Update Date columns must not be changed in ListB.

So I wrote this little PowerShell script to do the job.

Solution:
cls;

[void][reflection.assembly]::Loadwithpartialname("Microsoft.SharePoint")

$Site=[Microsoft.SharePoint.SPSite]("http://sharepoint01:1100")
$SiteWeb = $Site.openWeb()
$SourceList = $SiteWeb.Lists["ListA"]
$DestinationList = $SiteWeb.Lists["ListB"]

$ItemsColl = $SourceList.items

write-host "Total items found: " $SourceList.items.count

foreach ($Item in $ItemsColl) 
{

    write-host "Copying Item: " $Item["Title"]

    $NewItem = $DestinationList.items.Add()
    $NewItem["Title"] = $Item["Title"]
    $NewItem["Author"] = $Item["Author"]
    $NewItem["Editor"] = $Item["Editor"]
    $NewItem["Modified"] = $Item["Modified"]
    $NewItem["Created"] = $Item["Created"]
    $NewItem.Update()

}

$Web.dispose
$Site.dispose

write-host "All items have been copied successfully."

Wednesday, March 6, 2013

SharePoint 2007 - Top 100 Versioned Documents via SQL Query

In our local SharePoint environment the Content Database's size was going out of control and we have to identify the documents/items with the highest number of versions so that we can delete them and apply some sort of versioning limit to the document libraries.

I came across a treasure of SQL Queries at this post where Syed Adnan Ahmed has already written few excellent queries to analyze the CDB. My fav is to view the Top 100 versioned documents. 
SELECT TOP 100
Webs.FullUrl As SiteUrl, 
Webs.Title 'Document/List Library Title', 
DirName + '/' + LeafName AS 'Document Name',
COUNT(Docversions.version)AS 'Total Version',
SUM(CAST((CAST(CAST(Docversions.Size as decimal(10,2))/1024 As 
   decimal(10,2))/1024) AS Decimal(10,2)) )  AS  'Total Document Size (MB)',
CAST((CAST(CAST(AVG(Docversions.Size) as decimal(10,2))/1024 As 
   decimal(10,2))/1024) AS Decimal(10,2))   AS  'Avg Document Size (MB)'
FROM Docs INNER JOIN DocVersions ON Docs.Id = DocVersions.Id 
   INNER JOIN Webs On Docs.WebId = Webs.Id
INNER JOIN Sites ON Webs.SiteId = SItes.Id
WHERE
Docs.Type <> 1 
AND (LeafName NOT LIKE '%.stp')  
AND (LeafName NOT LIKE '%.aspx')  
AND (LeafName NOT LIKE '%.xfp') 
AND (LeafName NOT LIKE '%.dwp') 
AND (LeafName NOT LIKE '%template%') 
AND (LeafName NOT LIKE '%.inf') 
AND (LeafName NOT LIKE '%.css') 
GROUP BY Webs.FullUrl, Webs.Title, DirName + '/' + LeafName
ORDER BY 'Total Version' desc, 'Total Document Size (MB)' desc

Tuesday, March 5, 2013

SharePoint 2010 - Security Trimming

I came across a requirement where I have to hide the Ribbon for the readers in SharePoint 2010.
Following is the snippit of the control to do the magic:

<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageLists">
      Your ASP.NET control goes here
</SharePoint:SPSecurityTrimmedControl>

Permission values could be following:
  • ManageLists
  • ManageWeb

Tuesday, January 29, 2013

Friday, January 18, 2013

SharePoint 2013 - Administration Accounts

Multiple Server Farm

To manage SharePoint with multiple servers you need three types of roles/accounts:
Account Purpose
SQL Server service accountSQL Server prompts for this account during SQL Server Setup. This account is used as the service account for the following SQL Server services:
  • MSSQLSERVER
  • SQLSERVERAGENT
If you are not using the default instance, these services will be shown as:
  • MSSQL<InstanceName>
  • SQLAgent<InstanceName>
Setup user accountThe user account that is used to run:
If you run Windows PowerShell cmdlets that affect a database, this account must be a member of the db_owner fixed database role for the database.
  • Setup on each server computer
  • SharePoint Products Configuration Wizard
  • The Psconfig command-line tool
  • The Stsadm command-line tool
  • This account needs local admin access on the machine to run the SharePoint Setup.
Server farm accountThis account is also referred to as the database access account.
This account has the following properties:
  • It's the application pool identity for the SharePoint Central Administration website.
  • It's the process account for the Windows SharePoint Services Timer service.
  • This does not have to be the local account.


Start the installation with Setup user account and in SharePoint Configuration Wizard you will specify SQL Server service instance (because it will be on other server inside the farm) and Farm Account access.

Single Server Farm

To manage single server farm, all three roles can be handled by one account. So you need only local account (Setup user account) to do all the installation and configurations.

Start the installation with Setup user account and SharePoint Configuration Wizard will automatically pickup the SQL Server Instance and assign Setup user account as Farm account. 
See the single farm installation in here.

Ref: http://technet.microsoft.com/en-us/library/cc263445.aspx

SharePoint 2013 - Setup Development Environment

Pre-Requisite: Have your virtual machine ready with Microsoft Windows 2012 installed on it.

It will be a single server farm and following are the four steps to setup a SharePoint 2013 environment for development:
  1. Install Microsoft SQL Server 2012 (SP1)
    •  Select New SQL Server Stand-alone Installation
    • In the Installation wizard, under Feature Selection, select following features
  2. Install Microsoft SharePoint 2013
    • Install Pre-Requisite for SharePoint 2013
    • Launch SharePoint 2013 Setup and select Stand-alone installation on Server Type tab.
    • Launch SharePoint 2013 Product Configuration Wizard.
    • This wizard will perform configuration for SharePoint e.g. creating configuration database, registering features, provisioning Central Administration, creating sample data etc.
    • Launch Central Administration from Start menu
  3. Install Microsoft Visual Studio 2012
    • I am a developer so I will select all options to install
  4. Install Microsoft SharePoint Designer 2013

Monday, December 3, 2012

Backup and Restore SharePoint Site

Site Collection Backup and Restore

Backup: 
stsadm -o backup -url http://site1.com/sitecoll1 -filename c:\backup\backup1.dat
Restore: 
stsadm -o restore -url http://site2.com/sitecoll1 -filename c:\backup\backup1.dat -overwrite


Export and import a subsite, list, or library

Export:
stsadm -o export –url http://site1.com/sites/portal/Shared%20documents –filename c:\backup\lib.bak -quiet -overwrite 
Import:
stsadm -o import –url http://site2.com/sites/portal/Shared%20documents –filename c:\backup\lib.bak -quiet


Official SharePoint Documentation

I have recently contributed to the official SharePoint documentation for developement. Check it out here: https://docs.microsoft.com/en-us...