Monday, March 26, 2012

Delete all items from SPList - SharePoint 2010 PowerShell

I found this script in the internet, but don't remember where. Therefore I just put it here as is(Of course with all respect points to the anonymous writer of the script) :



[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

# "Enter the site URL here"
$SITEURL = "http://contoso"

$site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
$web = $site.OpenWeb()
"Web is : " + $web.Title

# Enter name of the List below
$oList = $web.Lists["MyList"];

"List is :" + $oList.Title + " with item count " + $oList.ItemCount

$collListItems = $oList.Items;
$count = $collListItems.Count - 1

for($intIndex = $count; $intIndex -gt -1; $intIndex--)
{
"Deleting : " + $intIndex
$collListItems.Delete($intIndex);
}

Sunday, March 25, 2012

Enable/Disable feature - SharePoint 2010 PowerShell

Some times you need just enable /disable feature .
So for me the good way is doing by PowerShell :

1. Get all installed features to the text file:

Get-SPFeature | Sort -Property Scope,DisplayName | FT -GroupBy Scope DisplayName,Id > c:\AllInstalledFeatures.txt

2. Go to the c:\AllInstalledFeatures.txt and find the relevant feature. Copy the guid.

3. Enable Feature:

Enable-SPFeature -identity "cdd0d039-d2d2-40c8-81fc-0d5657fc2962" -URL http://contoso.com

4. Disable Feature:

Disable-SPFeature -identity "cdd0d039-d2d2-40c8-81fc-0d5657fc2962" -URL http://contoso.com

Thursday, March 22, 2012

Restore Managed Metadata Term Stores - SharePoint 2010

Few days ago I needed to restore a managed metadata term stores, which were destroyed.
First of all I looked at metadataexport, but the problem is a lot of our data connected to the old managed metadata terms. Therefore when I exported it, it didn't work , due to guids which were changed.
So I needed to restore the Managed Metadata Term Stores from the DB backup.

1. I had to know what is the name of the relevant database:
Open - Central Admin - Application Management - Manage service application






2.In Service Applications - Managed Metadata Service - Properties:







3. Look at Database Server and Database Name of the relevant database:









4. After it I needed to restore (attach/detach of database ).I wrote it before

Wednesday, March 21, 2012

Backup - Restore Content Database to another farm SharePoint 2010 Power Shell

We need few steps to do it:
1. Backup data from source.
For this we need check which database we use for this web application









and backup the database:
From the SQL Server that your SharePoint farm users and where the instance of DB resides, backup the database.





2.Restore the database to the destination :
Take the backup file to the target SharePoint Farm's SQL Server (where we want to restore it to) and restore the database









Now we have a new content database, but we need to connect it to our SP.
Therefore we open SP Powershell :
3. Dismount old database:

Dismount-SPContentDatabase "Contoso_PortalContent_Old"

4. Mount new :
Mount-SPContentDatabase " Contoso_PortalContent_New" -DatabaseServer "contoso_db" -WebApplication http://contoso.com

Monday, March 19, 2012

SharePoint Power Shell Commands for adding solutions

Adding Solution:

Add-SPSolution "C:\WebPart.wsp"

Installing Solution:

Install-SPSolution –Identity WebPart.wsp –WebApplication http://contoso.com -GACDeployment


Update Solution if exists:

Update-SPSolution –Identity WebPart .wsp –LiteralPath “C:\WebPart .wsp” –GACDeployment