Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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