Can't run Velocity cmlet even if installed RRS feed

  • Question

  • I'm trying to create cache in a dynamic way to be able to run unit tests on the build server.

    I've saw this to run powershell scripts in c#:


          internal static Collection<PSObject> RunScript (string scriptText)
             Collection<PSObject> results;
             RunspaceConfiguration rsConfig = RunspaceConfiguration.Create ();
             PSSnapInException snapInException = null;
             PSSnapInInfo info = rsConfig.AddPSSnapIn ("Microsoft.Data.Caching.Commands", out snapInException);
             Runspace runspace = RunspaceFactory.CreateRunspace (rsConfig);
             runspace.Open ();
             Pipeline pipeline = runspace.CreatePipeline ();
             Command myCommand = new Command ("Use-CacheCluster");
             myCommand.Parameters.Add (new CommandParameter ("ConnectionString", "..."));
             myCommand.Parameters.Add (new CommandParameter ("Name", "..."));
             myCommand.Parameters.Add (new CommandParameter ("Provider", "System.Data.SqlClient"));
             pipeline.Commands.Add (myCommand);
             pipeline.Commands.AddScript (scriptText);
             results = pipeline.Invoke ();
             runspace.Close ();
             return results;

    but I have this error when the line "PSSnapInInfo info = rsConfig.AddPSSnapIn ("Microsoft.Data.Caching.Commands", out snapInException);" execute.

    Initialization method Grics.SoaLib.Caching.Tests.CacheManagerTest.Initialize threw exception. System.TypeInitializationException:  System.TypeInitializationException: The type initializer for 'Grics.SoaLib.Caching.CacheManager' threw an exception. --->  System.Management.Automation.PSArgumentException: The Windows PowerShell snap-in 'Microsoft.Data.Caching.Commands' is not installed on this machine..

    If I run this : PS C:\Program Files\Microsoft Distributed Cache\V1.0> Get-PSSnapIn -reg

    I get :
    Name        : Microsoft.Data.Caching.Commands
    PSVersion   : 2.0
    Description : Powershell Cmdlets for Microsoft Distributed Cache

    Name        : MSDeploySnapin
    PSVersion   : 1.0
    Description : MSDeploy PowerShell Snapin

    So it seems to be installed right.

    Is there anything I'm doing wrong?

    Wednesday, July 22, 2009 3:14 PM


All replies