Powershell, SharePoint

Starting the Microsoft SharePoint Foundation Sandboxed Code Service

I was trying to write a Powershell script that would deploy several features to a SharePoint 2013 environment but I kept getting an error:

Error occurred in deployment step ‘Activate Features’: Cannot start service SPUserCodeV4 on computer ‘SERVERNAME’

A Google search revealed that this was quite a common problem with quite a simple fix:

  1. Open the Central Administration site
  2. Open System Settings and click on Manage Service on server
  3. Check to see if Microsoft SharePoint Foundation Sandboxed Code Service is running (it should be stopped)
  4. Start the service and retry deploying the Sandboxed solution.

The problem I had was that I was using Powershell to do my deployment and didn’t want to have to include any manual steps. Unfortunately I couldn’t find any blogs that discussed how to do that.

After a bit of trouble shooting, this is the script that I came up with

$svcSPUserCode = "Microsoft SharePoint Foundation Sandboxed Code Service"
 Get-SPServiceInstance -server $env:COMPUTERNAME | where-object {$_.TypeName -eq $svcSPUserCode} | Start-SPServiceInstance -confirm:$false > $null

Broken down this script will:

  • Get all SharePoint Services running on the local machine
 Get-SPServiceInstance -server $env:COMPUTERNAME
  • Find the object where the TypeName matches “Microsoft SharePoint Foundation Sandboxed Code Service”
  • Starts the Service

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s