Skip to content

Instantly share code, notes, and snippets.

@nshenoy
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshenoy/9530080 to your computer and use it in GitHub Desktop.
Save nshenoy/9530080 to your computer and use it in GitHub Desktop.
InitialSessionState state = InitialSessionState.CreateDefault();
state.ImportPSModule(new string[] { "DistributedCacheAdministration", "DistributedCacheConfiguration" });
state.ThrowOnRunspaceOpenError = true;
using(Runspace rs = RunspaceFactory.CreateRunspace(state))
{
rs.Open();
using(Pipeline pipeline = rs.CreatePipeline())
{
Command command = new Command("Use-CacheCluster");
command.Parameters.Add(new CommandParameter("Provider", "System.Data.SqlClient"));
command.Parameters.Add(new CommandParameter("ConnectionString", "Data Source=.\\SQLEXPRESS;Initial Catalog=AppFabric;Integrated Security=True"));
pipeline.Commands.Add(command);
Trace.WriteLine(string.Format("Invoking: {0} {1}",
command.CommandText,
string.Join(" ", command.Parameters.Select(p => string.Format("-{0} \"{1}\"", p.Name, p.Value)))));
pipeline.Invoke();
}
Trace.WriteLine("I expect to see this line and all other traces after this.");
}
Trace.WriteLine("Ending program");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment