static void Main(string[] args)
        {
            try
            {
                RemotePowerShellClient client = new RemotePowerShellClient("PowerShellClient");

                Console.WriteLine("Press any key to start");
                Console.ReadKey();
                Console.WriteLine();

                string startResponse = client.StartPowerShell(Providers, PerfCounters);
                Console.Write(startResponse);

                RestartIis(client, "test1");

                string command;
                do
                {
                    command = Console.ReadLine();
                    ExecuteCommand(client, command);
                } while (!string.Equals("exit", command, StringComparison.InvariantCultureIgnoreCase));

                client.Close();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.ToString());
            }

            Console.WriteLine("\n\nPress any key to exit");
            Console.ReadKey();
        }
 private static void ExecuteCommandBatch(RemotePowerShellClient client, string[] commands)
 {
     foreach (string command in commands)
     {
         ExecuteCommand(client, command);
     }
 }
 private static void ExecuteCommand(RemotePowerShellClient client, string cmd)
 {
     string commandResponse = client.SendCommand(cmd);
     Console.WriteLine(commandResponse);
 }
 private static void StopPerfCounters(RemotePowerShellClient client)
 {
     ExecuteCommandBatch(client, new string[] {
         @"logman stop infrastructure_counters",
         @"logman delete infrastructure_counters",
         @"copy .\*.blg $testOutputDir",
     });
 }
 private static void StartPerfCounters(RemotePowerShellClient client)
 {
     ExecuteCommandBatch(client, new string[] {
         @"del perfcounters*.blg",
         @"logman create counter infrastructure_counters -cf perfCounters.txt -si 1 -o perfcounters.blg",
         @"logman start infrastructure_counters",
     });
 }
 private static void RestartIis(RemotePowerShellClient client, string testName)
 {
     ExecuteCommandBatch(client, new string[] {
         string.Format(@"$testOutputDir = $perfOutputDir + ""\{0}""", testName),
         @"iisreset",
         @"net start w3svc",
     });
 }