How to register your full-trust proxy with SharePoint 2010

Posted on 12/7/2009 @ 3:11 AM in #SharePoint by | Feedback | 2598 views

I will eventually link this blogpost to a series of blogposts on Sandbox solutions, but for now, Here is a tiny little powershell script that will allow you to register a full-trust proxy that you can then use with sandbox solutions in SharePoint 2010. Put this in a file called “RegisterProxy.ps1”.

   1: Param($assemblyName, $typeName)
   2: $userCodeService = [Microsoft.SharePoint.Administration.SPUserCodeService]::Local
   3: $proxyOperationType = new-object -typename Microsoft.SharePoint.UserCode.SPProxyOperationType -argumentlist $assemblyName, $typeName
   4: $userCodeService.ProxyOperationTypes.Add($proxyOperationType)
   5: $userCodeService.Update()

The usage is hella simple -

From powershell, run the following command -

   1: .\RegisterProxy.ps1 -assemblyName "SandBoxWebPartWithProxy, Version=, Culture=neutral, PublicKeyToken=64b818b3ff69ccfa" -typeName "SandBoxWebPartWithProxy.ProxyCode.FileCreateOperation"

You can also easily verify if the proxy got registered or not! by running the below -

   1: [Microsoft.SharePoint.Administration.SPUserCodeService]::Local.ProxyOperationTypes

Sound off but keep it civil:

Older comments..

On 1/12/2011 12:47:59 PM David Smith said ..
From where do I place and run the file? I am getting an error:

cant find type SPCodeService

On 2/18/2011 2:11:46 AM Olaf Keijsers said ..
You probably need to run this from a SharePoint 2010 Management Shell, so that the correct assemblies are already loaded for you into PowerShell. Not really sure as I haven't tried it though.

On 2/28/2011 7:12:50 PM mpalmer said ..
yup - running from the SharePoint 2010 Management Shell works

On 7/27/2011 5:03:10 AM Raviraj said ..
what I did is :1.I created RegisterProxyScript.ps1 file

2.I opened it and put all that 5 lines of code mentioned above

3.I insatalled my assembly in GAC, got its Name but not sure about its type..(Does any one here know how to get the type of that assembly)...What i did it i think the type is of format ProjectName.FolderNameOfthatCSFile.NameOfthatCSFile

4.Then I opened right clicked that .ps1 file and say edit.

5.Then in that window i click,"start powershell.exe" icon

6.Then .exe will execute, there i typed the following:

.\filename.ps1 -assemblyName "AssemblyName" -typeName "TypeOfThatAssembly"

7. I still get an error saying the assembly was not loaded.

ANY SOLUTIONS???PLS does any1 can tell the way to register and possibly how to know the correct type ??

On 1/19/2012 5:06:21 AM said ..
Raviraj, put this line on the top of your script:

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

On 6/19/2012 7:30:56 AM NGK Prasad said ..
I have confirmed that proxy got registered by the above approaches, my proxy operation got registered , still i am getting the error "This code is calling a privileged proxy operation that is not available on this farm. Please contact your farm administrator"