User Word Automation Service using PowerShell

With PowerShell also possible to use Word Automation Service to convert documents to pdf, xps, etc formats.

Execute below script in PowerShell on your SharePoint Server. Don’t forgot to make necessary changes in script as per your environment. Also Word Automation Service should be in running state.


$jobSettings = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobSettings

$jobSettings.OutputFormat = "PDF"

$job = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob("Var Word Automation Service", $jobSettings)

$job.UserToken = (Get-SPWeb http://VarSiteName).CurrentUser.UserToken

$job.AddFile("http://VarSiteName/Document%20Library/VarDocName.docx", "http://VarSiteName/Document%20Library/VarDocName.pdf")


For UI based solution check this link: SharePoint Document Converter

Play with SharePoint 2010 List using PowerShell

In this post, we will learn how to do basic operations on SharePoint list using PowerShell.

Lets start with List creation

$spAssigment = Start-SPAssignment    #Use to dispose SPWeb safely
$spWeb = Get-SPWeb ServerURL -AssignmentCollection $spAssignment     #Get SPWeb Instance
$spWeb.ListTemplates | Select Name, Description    #Display List of Templates Available
$spTemplate = $spWeb.ListTemplates["Custom List"]     #Create SPTemplate instance of Type Custom List
$spWeb.Lists.Add("List Title", "Description", $spTemplate)     #Add list to site

Add list to quick launch and fields to list

$spList = $spWeb.Lists["List Title"]    #Get list instance
$spList.OnQuickLaunch = $True    #Set true to display in Quick Launch
$spList.Update()    #Update list to reflect changes in site
$spFieldType = [Microsoft.SharePoint.SPFieldType]::Text      #Get Field type to create
$spList.Fields.Add("My Column", $spFieldType, $false)      #Add new field to list

Create View and set fields for view

$spViewQuery = “<OrderBy><FieldRef Name=”"Modified”" Ascending=”"False”" /></OrderBy>”
$spViewFields = New-Object System.Collections.Specialized.StringCollection    #Create string collection object
$spViewFields.Add("Title")    #Add columns
$spViewFields.Add("My Column")
$spViewName = "My View"        #Set view name
$spListView = $spList.Views.Add($spViewName, $spViewFields, $spViewQuery, 100, $True, $False, “HTML”, $False)    #Add view to list
$spListView.DefaultView = $True       #Set view as default
$spListView.Update()    #Update view to reflect changes in site

Add few List Items

$spListItem = $spList.Items.Add()    #Add new list item object
$spListItem["Title"] = "First Item"    #Set field value
$spListItem["My Column"] = "My Text for first item"
$spListItem.Update()    #Update list item object to reflect changes in site

$spListItem = $spList.Items.Add()
$spListItem["Title"] = "Second Item"
$spListItem["My Column"] = "My Text for second item"

Update List Items

$spListItems = $spList.Items    #Get list item collection
$spListItemsCount = $spListItems.Count    #Get list items total count
for($Counter = $spListItemsCount-1; $Counter -ge 0; $Counter--)
    $spListItem = $spListItems[$Counter]    #Get list item via index
    $spListItem["Title"] = "Updated Title" + $Counter
    $spListItem["My Column"] = "My Column" + $Counter

Delete List Items

for($Counter = $spListItemsCount-1; $Counter -ge 0; $Counter--)
    $spList.Items[$Counter].Delete()    #Delete list item

Delete List


Finally Dispose web object

Stop-SPAssignment $spAssignment

Happy Reading!!!

Extract WSP Solution files from SharePoint 2010 Farm

Before deploying updated WSP solution to SharePoint farm, administrators wish to take backup of current deployed solution in production servers just to stay on safe side. There is no option in CA to achieve this. Here is the script which gives us power to do.

(Get-SPFarm).Solutions | ForEach-Object{$var = (Get-Location).Path + "\" + $_.Name; $_.SolutionFile.SaveAs($var)}

To download single file use below script (Replace the YourSolutionFileName with actual WSP file name like abc.wsp):

$var = (Get-Location).Path + "\" + "YourSolutionFileName";(Get-SPFarm).Solutions["YourSolutionFileName"].SolutionFile.SaveAs($var)

$var = (Get-Location).Path + “\” + “YourSolutionFileName”; (Get-SPFarm).Solutions[“YourSolutionFileName”].SolutionFile.SaveAs($var)

SharePoint 2010 File Storage System

SharePoint provide us a nice UI to store and read documents. But what happen behind the scene. Where it store all the files???

File System or Content Database

When we open document library in windows explorer view, SharePoint allow us to delete/update/add files as we do in the normal file system. So, what does it mean that files are stored in a physical location.

Nope. Not with SharePoint. It keep all the documents in a database. Ooooh database!!!

Doesn’t sound good to keep the documents in a database. What if my file size is big. Will it not slow down the performance as SQL BLOB operation are costly than accessing file from a physical path. Even SQL Express editions has limitation on database size (approx 10GB i think). Do to SQL storage, SharePoint allow file upload of max 2GB.

Cons with Content Database

– Costly SQL operations

– Limitation on file size

– Huge database size due to big files

Pros with Content Database

– Easy backup/restore process. As all data in one single file

With release of SharePoint, we have the option to configure storage of SQL Binary Large OBjects (BLOB) to physical file system. In SQL Server 2008 (including express 🙂 ), Microsoft provided an add-on feature pack called Remote Blob Storage (RBS) used for storage of BLOB to physical location.

Lets start how we can enjoy RBS feature with SharePoint 2010. Below post will explain how to configure RBS for SharePoint 2010.

Step 1. Select the Content database for RBS. (It is possible to limit the RBS per Web Application level)

a. Open Central Administration Site -> Application Management -> Manage Content Databases

b. Select Web Application for which you want to enable RBS. Note down the content database name for selected Web Application.

Step 2. Enable file stream on SQL Server 2008/R2 (including express edition)

a. Open SQL Server Configuration Manager -> SQL Server Services

b. Right click SQL instance on which SharePoint is running, and then select properties.

c. Select FILESTREAM tab -> checkbox Enable FILESTREAM for Transact-SQL access.

d. Select other checkboxes as per your requirement and click Apply -> Ok.

e. Open SQL Server Management Studio. Execute following query for Web Application Database as selected in step 1.

EXEC sp_configure filestream_access_level, 2

Step 3. Provision a BLOB store

a. Open SQL SERVER Management Studio. Execute below queries for Web Application Database as selected in step 1. Note: Replace WSS_Content as per step 1.

use [WSS_Content]
if not exists 
(select * from sys.symmetric_keys 
where name = N'##MS_DatabaseMasterKey##')
create master key encryption by password = N'Admin Key Password !2#4'
use [WSS_Content]
if not exists 
(select groupname from sysfilegroups 
where groupname=N'RBSFilestreamProvider')
alter database [WSS_Content]
add filegroup RBSFilestreamProvider contains filestream
use [WSS_Content] 
alter database [WSS_Content]
 add file (name = RBSFilestreamFile, filename = 
to filegroup RBSFilestreamProvider

Step 4. Install RBS.

a. Download installation package using links: X64 Package X86 Package IA64 Package

b. Install RBS client library on the web server. Note: Replace WSS_Content as per step 1 and DBInstanceName as per your SharePoint environment. Locate cmd prompt to download folder and execute following command.

msiexec /qn /lvx* rbs_install_log.txt /i RBS-x64.msi TRUSTSERVERCERTIFICATE=true FILEGROUP=PRIMARY DBNAME="WSS_Content" DBINSTANCE="DBInstanceName" FILESTREAMFILEGROUP=RBSFilestreamProvider FILESTREAMSTORENAME=FilestreamProvider_1

Step 5. Enable RBS

a. Open SharePoint 2010 Management Shell and execute following commands. Note: Replace WSS_Content as per step 1.

$cdb = Get-SPContentDatabase <ContentDatabaseName>
$rbss = $cdb.RemoteBlobStorageSettings

Step 6. Test RBS Installation
a. Browse to RBS directory store and confirm folder is empty.
b. Upload a file to SharePoint Web Application (of atleast size 100 Kb).
c. Browse to the file in the RBS directory store and open the file with the most recent modified date. This should be the file you have uploaded.

Cheers !!!

SharePoint 2010 complete farm installation without domain account

Usually while SharePoint installation we have to select between Standalone and Farm installation. For Standalone installation we don’t need a domain account. It is automatically configured to use local service accounts. But if we have installed SharePoint with Farm Complete setting and still want to use the local service account during for SharePoint configuration.

In normal scenario, we get the below error message while running SharePoint configuration Wizard first time.

The specified user xxx is a local account. Local accounts should only be used in stand alone mode.

Now comes the tricky part. How to bypass this step. This can be achieved by performing below steps:

1. Run SharePoint PowerShell with administrator privileges

2. Run command: New-SPConfigurationDatabase (Provide all the necessary parameters)

3. Make sure provided service account is member of local Administrator group.

4. Now run the SharePoint configuration wizard again. You won’t be asked to enter the domain account.


The website declined to show this webpage

I freshly installed SharePoint 2010 on my Windows 2008 server VM. Everything working fine, i installed few more softwares like Commerce Server, Team Foundation Server 2010. After that i tried to access my SharePoint Central administration page and problem started.  I continuous to get the  error “The website declined to show this webpage. Possible cause: The site require user to log in” when try to open central administration site. Even i verified the credential, that was fine. To troubleshoot i checked the following things:

1. AppPool and Central Service used for site should be running.

2. Verified the credentials under which app pool running.

All above was fine. I was wondering what is the issue. After so much tweaking i found that issue is with the app pool used to run Central Administration site. AppPool was running with .NET Framework version “No Managed Code”. Strange is all AppPool running with that framework version. I set the AppPool .NET Framework version to “V.2.0”, restarted the app pool and it started working. 🙂

Usefull SharePoint 2010 PowerShell Commands

Customize Out of the box Application pages
Get-SPCustomLayoutsPage -Identity “AccessDenied | Confirmation | Error | Login | RequestAccess | Signout | WebDeleted
Set-SPCustomLayoutsPage -Identity “RequestAccess” -RelativePath “/_layouts/custompages/reqacc.aspx” -WebApplication “{replace with web app url}”

%d bloggers like this: