About Me

Having 12 years experience in Microsoft technologies.Since more than 7 years working in SharePoint technologies. Expert in providing consultation for SharePoint projects. Hands on with development and administration.

Wednesday 19 December 2012

PowerShell script to deploy Multiple Sandbox solutions

Applies to SPFoundation 2010, SP 2010, SPFoundation 2013,SP 2013

Points to be noted:
1. Replace $siteURL with url
2. All wsps should be in the current directory of the script (.ps1)

Add-PsSnapin Microsoft.SharePoint.PowerShell
$logfile=$CurrentDir + "\log.log"
$siteURL = "
xxxxxxx"
Start-Transcript $logfile
#Do not modify anything in the script from here onwards
function Get-ScriptDirectory
{
 $Invocation = (Get-Variable MyInvocation -Scope 1).Value
 Split-Path $Invocation.MyCommand.Path
}

function Deploy-Solution{
param(
[string]$physicalPath,
[string]$name)

$SolutionName = $name
$SolutionPath = Join-Path ($physicalPath) $SolutionName
echo "Extracting information from $physicalPath"

$Solution = Get-SPUserSolution -site $siteURL | Where { ($SolutionName -eq $_.Name) }  -ErrorAction SilentlyContinue
if ($Solution -ne $null)
{
    if($Solution.Status -eq "Activated")
    {
    Write-Host 'Poweshell Script will now retract solution:' $SolutionName
    Uninstall-SPUserSolution -Identity $SolutionName -Site $SiteURL -Confirm:$false
    Write-Host 'Successfully retracted solution:' $SolutionName
    }
    Write-Host 'Removing Solution:' $SolutionName
    Remove-SPUserSolution -Identity $SolutionName -Site $siteURL -Confirm:$false
    Write-Host 'Successfully removed Solution:' $SolutionName
}

Write-Host 'Poweshell Script will now add solution:' $SolutionName
Add-SPUserSolution –LiteralPath $SolutionPath -Site $SiteURL
Write-Host 'Poweshell Script will now deploy solution:' $SolutionName
Install-SPUserSolution -Identity $SolutionName -Site $SiteURL
Write-Host 'Poweshell Script has finished deployment of solution:' $SolutionName
}

#Get Current Physical Path
$currentPhysicalPath = Get-ScriptDirectory

#Iterate through all .wsp files in the current Physical Path to deploy solution
get-childitem $currentPhysicalPath -include *.wsp -recurse | foreach ($_) {Deploy-Solution $currentPhysicalPath $_.name}

Stop-Transcript
#Remove SharePoint Snapin
Remove-PsSnapin Microsoft.SharePoint.PowerShell


Echo Finish

PowerShell script to deploy Sandbox solution

Applies to SPFoundation 2010, SP 2010, SPFoundation 2013,SP 2013

In general we will write a script to deploy farm solutions. But we will upload sandbox solutions into site collection solution gallery. What if, we want to automate the process to deploy sandbox solution without uploading.... here is the script

Points to be noted:
1. The .wsp should be in the current directory of the script (.ps1)
2. Replace $solutionName with your solution name.
3. Replace $SiteURL with your site collection url.

Add-PsSnapin Microsoft.SharePoint.PowerShell
Write-Host 'Poweshell Script will initialize parameters'
$CurrentDir=$args[0]
$solutionName="xxxx.wsp"
$SolutionPath=$CurrentDir + "\"+$solutionName
$logfile=$CurrentDir + "\log.log"
$SiteURL = "xxxxxxx"

Start-Transcript $logfile
$errorActionPreference = 'Inquire'

$solution = Get-SPUserSolution -site $siteURL | Where { ($solutionName -eq $_.Name) }  -ErrorAction SilentlyContinue 
try
{
if ($solution -ne $null)
{
if($solution.Status -eq "Activated")
{
Write-Host 'Poweshell Script will now retract solution:' $solutionName

Uninstall-SPUserSolution -Identity $solutionName -Site $SiteURL -Confirm:$false
Write-Host 'Successfully retracted solution:' $solutionName
}
Write-Host 'Removing Solution:' $solutionName
Remove-SPUserSolution -Identity $solutionName -Site $siteURL -Confirm:$false
Write-Host 'Successfully removed Solution:' $solutionName
}

Write-Host 'Poweshell Script will now add solution:' $solutionName
Add-SPUserSolution –LiteralPath $SolutionPath -Site $SiteURL
Write-Host 'Poweshell Script will now deploy solution:' $solutionName
Install-SPUserSolution -Identity $solutionName -Site $SiteURL
Write-Host 'Poweshell Script has finished deployment of solution:' $solutionName
}

catch [system.Exception]
{
Write-Error 'An Unknown error occured while trying to deploy/redeploying the solution:' $_.Exception.Message
}


Stop-Transcript
Remove-PsSnapin Microsoft.SharePoint.PowerShell

Happy powershell programming......

Wednesday 10 October 2012

IN and OUT of SharePoint 2010 Sandbox solutions

Following are the major limitations for Sandbox solutions.


  • Scoped access to the SharePoint object model: Can able to access objects at the site collection level and below (SPSite, SPWeb, etc..). Cannot access to SPFarm & SPWebApplication              
  • Limited access to external (non-SharePoint) resources such as the file system based on Code Access Security (CAS) policies.
  • No code-based workflows, which use Workflow Foundation in .NET 3.5.
Sandbox solution execution process:              
    When a request is executed in the SharePoint server, it is passed to the User Code Service SPUCHostService.exe). In a farm solution, this calls the SharePoint DLL (Microsoft.SharePoint.dll) directly. In a sandboxed solution, however, this is passed to the Sandbox Worker Process(SPUCWorkerProcess.exe). This provides two important functions. First, requests for any non-SharePoint resources such as the file system are filtered through the CAS policy. The request is rejected if the needed access is not allowed. Secondly, it verifies that the SharePoint objects being used are within the scopeallowed for sandboxed solutions. Calls that manipulate the SPFarm object, for example, will be blocked.

Critical and important/technical question: Location of the sandbox solutions and Where are Assemblies in Sandboxed Solutions Deployed to?

The generic answer is - Since we are uploding solutions @ solutions gallery, it's abvious that the storage location for the sandbapx soloution is SharePoint content DB. It;s very easy to answer isn't it.?

YES, the entry is available in content database, however the DLL will not be stored in DB. That's the trick here... then where is the dll? good question. here is the answer:


 When a sandboxed solution is accessed for the first time, such as when a user navigates to a page that contains a Web Part from a sandboxed solution, any assemblies in the solution are extracted from the package in the gallery and copied to the file system of the server that is handling the sandboxed request.
 
The location is C:\ProgramData\Microsoft\SharePoint\UCCache. The executable of this service is SPUCHostService.exe. The server that handles the sandboxed request is not necessarily the front-end web server that is handling the initial HTTP request:
 
The Microsoft SharePoint Foundation Sandboxed Code Service can be run on back-end application servers in the farm instead. Because the sandboxed user process (SPUCWorkerProcess.exe) cannot copy anything to the file system, the copying is done by the Microsoft SharePoint Foundation Sandboxed Code Service.
 
The assemblies of a sandboxed solution do not stay in the file cache perpetually. When the user session that accessed the solution ends, the assemblies stay in the cache for only a short time, and they may be reloaded from there if another user session accesses them. Eventually, if they are not accessed, they are removed in accordance with a proprietary algorithm that takes into account how busy the server is and how much time has gone by since the assemblies were last accessed. If the sandboxed solution is used after that time, the assemblies are extracted again and copied to the UCCache.

Monday 27 February 2012

Step by Step Installtion instructions for SharePoint 2010

Please refer previous posts before understanding current one

post2 - Other prerequisites & service accounts needed to set up a farm 


SharePoint 2010 Installation Instructions
Let’s start with the installation on the Application Server. This is where I would normally want my Central Administration to be accessible from, especially if my web server is publically accessible.
Application Server Install
1.     Ensure all prerequisites from Hardware, Software, Miscellaneous and Service Accounts above
2.     Make sure your media is available in the DVD drive of the server or accessible locally or a network share
3.     Under Administrative Tools à Server Manager à Configure IE ESC, I normally turn it off for Administrators
image
4.     Under Control Panel à User Accounts à User Accounts à Change User Account Control settings, I normally set it to Never notify
image
5.     Run the splash page
image
6.     Click on and Install software prerequisites
image
image
image image
7.     Click on Install SharePoint Server from the splash page
image
8.     Enter your Product Key and hit Continue
image
image
9.     Choose a Server Farm installation
image
10.  Choose a Complete Server Type and specify the File Location if applicable

image
image
11.  Once installed, Run the SharePoint Products Configuration Wizard now
image image
12.  Click Yes to reset services
image
13.  Create a new server farm
image
14.  Enter the configuration database settings along with your username/password for your Farm Administration service account defined above in the prerequisites
image
15.  Enter a Passphrase (this is used to add servers to the farm at a later point) – don’t forget to log this somewhere!
image
16.  Specify a Port Number you would like to use (or use the default) for Central Administration and choose the authentication provider
image
image
image
image
17.  Once you hit Finish, it will automatically open the Central Administration website; click No to not participate in the Customer Experience Improvement program (unless you really want to!)
image
18.  You can configure the farm using the Wizard or manually, I would recommend using the Wizard (and disable the services you want after the install) but if you are confident you can just install the services you need manually
image
19.  The first part of the configuration wizard is to select the services to run on the farm. As of SharePoint 2010 beta, there was a problem getting user profiles working without using the Farm Administration account, so I would advise using this account for now, I think it can be changed later without much work.
20.  Select the farm administration service account from the dropdown and select the services you want to run on the farm and press ok
image
image
21.  If you now look at your SQL Server, you will notice a whole wack of new databases have been created
22.  At this point it will ask you to create your first SharePoint site configured at the port 80 web application. I usually skip this step because I want my own custom web applications to be created. Go ahead and create your own Web Application & Site Collection at this point if you like
23.  At the end it will give you a completion screen notifying you of all the services that have been installed
image
24.  The next step is to change the SharePoint Web Services Root application pool to run as the Farm Administrator account by changing it in advanced settings and starting it (note: I’m not sure if this is a bug or not as you would think this would be automatically done for you)
image
image
25.  Next start the Microsoft SharePoint Foundation Sandboxed Code Service (if you are allowing Sandboxed solutions on your farm). This can be found under Central Administration à Manage Services on server
image
26.  Next configure the Search Service Application under Central Administration à Manage Services on server à Search Service Application à Search Service Applications
image
image
i.              Change the Default content access account to the domain service account that was created (optional) as well as the Contact e-mail address to the SharePoint Administrator defined in the prerequisites
image
ii.             Create a crawl schedule under Search Service Application à Content Sources à Local SharePoint Sites. I usually do a full crawl every day at midnight and incremental crawls every hour after that.
image
27.  Next step is configuring the User Profiles. This is probably the trickiest part of the configuration. If something goes wrong here, there are many resources out there in the www to help you track down your issue and if needed, the best resource that I have found is by Spencer Harbar and outlined here: http://www.harbar.net/articles/sp2010ups.aspx
***Note make sure “replicate directory changes” is set for the farm administrator service account as defined above in the prerequisites.
a.     To start this user profile synchronization service, it seems that the farm administrator account needs to be a member of the local administrator group on the application server (Needs verification). Note: If you are just adding this account to the admin group now, you should restart the SharePoint Timer Service under startàrun àservices.msc before continuing
b.     Under Central Administration à Manage Services on Server à start the User Profile Synchronization Service
image
c.     Enter the credentials of the Farm Administrator Service Account defined in the prerequisites above and press Ok
image
d.     Run IISReset from the run menu or command prompt
e.     At this point, a timer job called ProfileSynchronizationSetupJob will run for a while which you can see at Central Administration à Monitoring à Check Job status
image
image
f.      You should wait until the service is completely started before proceeding
image
g.     At this point, you should have the Forefront Identify Manager Service and the Forefront Identity Manager Synchronization Service running in your services.msc as your farm administrator account
image
h.     Run iisreset in startàrun or from the command prompt (if you don’t do this you will get an error when you perform the next step that I outline here: http://www.khamis.net/blog/Lists/Posts/Post.aspx?List=6c8a23d1-47ea-47e5-b56f-2bc57cb95b93&ID=28 )
i.      Next step is to actually configure the User Profile Service Application under Central Administration à Manage service applications (click on the User Profile Service Application link)
image
j.      Click on the Configure Synchronization Connections link under Synchronization
image
k.     Create a New Connection
image
l.      Enter the appropriate settings for the synchronization connection:
image
                                          i.    Give the connection a name
                                         ii.    Enter the domain controller name as per the prerequisites defined earlier (e.g. type nslookup from a computer on the domain) or enter the forest name (i.e. mydomain.com) and leave it on Auto discover domain controller (I would advise specifying the domain controller as I have had problems with auto-discover mode).
                                        iii.    Under account name/password use the farm administration account that has replicate directory rights as per the prerequisites defined earlier
                                        iv.    Press the Populate Containers button, select the containers you want synchronized and press ok. Be careful that the farm administration service account you specified as having replicating directory changes is applicable to the domain containers you select. Ensure that you only select the OU (i.e. SharePoint Users) that you want synched or else it will take a long time to complete the synch.
                                         v.    Iisreset at this point (might not be needed)
image
m.   Next we want to start a full profile synchronization under Central administration à Manage Services on Server à User Profile Service Application à Start Profile Synchronization
image
image
n.     At this point, it will do a bunch of stuff in user profile synchronization, a little known fact is that you can actually see the progress via a shell that Microsoft has created located here: C:\Program Files\Microsoft Office Servers\14.0\Synchronization Service\UIShell\MSIISClient.exe. It has to go through a lot of successful steps before it completes:
image
o.     To see that the user profile synchronization actually worked go to Central Administration à Manage Service Applications à User Profile Service Application à Manage User Profiles and put your domain in the find box and it should show you a bunch of the user profiles that have been synched
image
image
p.     By default the user profile synchronization occurs every day at 1am but this can be changed under Central Administration à Manage Service Applications à User Profile Service Application à Configure Synchronization Timer Job
image
image
28.  Set up outgoing email, under Central Administration à System Settings, Note: You need the Outbound SMTP server and from/to SharePoint administrator email address as defined in the prerequisites
image
image
29.  Optional - Set up incoming email, under Central Administration à System Settings, Note: You need the SMTP service setup locally on the Windows Server OS before this is done as defined in the prerequisites
image
image
30.  Setup My Sites under Central administration à Manage Services on Server à User Profile Service Application à Setup My Sites. Fill in all the properties according to your farm requirements.
a.     What you can do here at this point is create a new web application to host your My Sites before configuring My Sites and point to it here
b.     Also, create a web application/site collection that will host your preferred Search Center and point to it here
image
c.     Under Site Naming Format, I always to be on the safe side, set it to use Domain and user name
image

Web Server Install
Now that we have the main Application server up and running, the next step is to add the web server and in fact any other server to the farm
1.     Ensure all prerequisites from Hardware, Software, Miscellaneous and Service Accounts above
2.     Make sure your media is available in the DVD drive of the server or accessible locally or a network share
3.     Under Administrative Tools à Server Manager à Configure IE ESC, I normally turn it off for Administrators
image
4.     Under Control Panel à User Accounts à User Accounts à Change User Account Control settings, I normally set it to Never notify
image
5.     Run the splash page
image
6.     Click on and Install software prerequisites
image
image
image image
7.     Click on Install SharePoint Server from the splash page
image
8.     Enter your Product Key and hit Continue
image
image
9.     Choose a Server Farm installation
image
10.  Choose a Complete Server Type and specify the File Location if applicable

image
image
11.  Once installed, Run the SharePoint Products Configuration Wizard now
image image
12.  Click Yes to reset services
image
13.  Connect to an existing server farm
image
14.  Enter the name of the Database Server and the Configuration Database name
image
15.  Enter the same Passphrase that was used when setting up the Application server
image
16.  If you want to host the Central Administration web site on this web server, you can do this under Advanced Settings, otherwise hit next
image
image
image
17.  When you hit Finish, it will open the Central Administration, again, I would advise using the Wizard
image
image
18.  The next step is to change the SharePoint Web Services Root application pool to run as the Farm Administrator account by changing it in advanced settings and starting it
image
image
19.  Once all your servers have been added to the farm, you should now select and deselect the services you would like to run on each web/application server under Central Administration à Manage Services on Server. This should clearly be thought out and planned beforehand as to which services should reside on which server based on their roles and perceived load. Notice the Server drop down from where you can select the server at the top right [12].
image

20. Just start and stop the services you need for each web or application server from this page

**Update**:  There have been a lot of people asking which services to turn on and off for the application and web servers.  Jeff Cate has just posted a great blog on SharePointSolutions.com [13] which talks about this.  I have been trying to find a good reference for this for ages!  In it he indicates that:
The web front end should have these services:
  1. Microsoft SharePoint Foundation Web Application (this is what turns IIS into a SharePoint “page-serving” machine)
  2. Search Query and Site Settings Service (the process that takes the user’s query string and looks it up in the index)
  3. SharePoint Server Search Service (but just the functionality that is necessary for the query processor)
  4. Central Administration (assuming you didn’t decide to move it to the Application Server)

And the application server should have:
  1. Access Database Service
  2. Application Registry Service
  3. Business Data Connectivity Service
  4. Excel Calculation Services
  5. Managed Metadata Web Service
  6. Microsoft SharePoint Foundation Incoming E-mail
  7. Microsoft SharePoint Foundation Workflow Timer Service
  8. PerformancePoint Service
  9. Secure Store Service
  10. SharePoint Server Search (but just the scheduled content crawling and indexing building functionality)
  11. User Profile Service
  12. Visio Graphics Service
  13. Web Analytics Data Processing Service
  14. Web Analytics Web Service
  15. Word Automation Services
  16. Word Viewing Service
References