Total Pageviews

5 Jun 2013

Run C# Code from Powershell that uses SharePoint DLL's

Here is a very nice article
http://blogs.technet.com/b/stefan_gossner/archive/2010/05/07/using-csharp-c-code-in-powershell-scripts.aspx

For example:

Code:
$Assem = ( 

"Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" , 

"Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 

) 


$Source = @" 

using Microsoft.SharePoint.Publishing.Administration; 

using System; 


namespace StefanG.Tools 

{ 

public static class CDRemoteTimeout 

{ 

public static void Get() 

{ 

ContentDeploymentConfiguration cdconfig = ContentDeploymentConfiguration.GetInstance(); 

Console.WriteLine("Remote Timeout: "+cdconfig.RemoteTimeout); 

} 


public static void Set(int seconds) 

{ 

ContentDeploymentConfiguration cdconfig = ContentDeploymentConfiguration.GetInstance(); 

cdconfig.RemoteTimeout = seconds;

cdconfig.Update();

} 

} 

} 

"@ 


Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp 


[StefanG.Tools.CDRemoteTimeout]::Get()


[StefanG.Tools.CDRemoteTimeout]::Set(600)


No comments:

Post a Comment