title: C# and PowerShell: How do I add comma delimited parameters?
body: <p>I'm trying to run a command and it's not working, here is the command which works just fine at the PowerShell command prompt:</p>
  
  <p><code>mcli-add DiskLocator -r diskLocatorName=XAShared-2015-10-13, siteName=mysite, storeName=pvs_prod</code></p>
  
  <p>Here is the code I'm trying to use to make that command work. I've tried a number of methods (see commented lines), from having it all in one line to having it in separate parameters to not putting the commas and putting the commas. The parameter name is -p, the parts after that are the arguments.</p>
  
  <p>Here's the code as I have it now, attempting to capture the output which seems successful but it's not actually doing anything, I'm getting <code>Executing: Add DiskLocator</code> in the event log but I am not seeing the second result which should be <code>Add Succeeded.</code> followed by a result ID:</p>
  
  <pre><code>using (Runspace runspace = RunspaceFactory.CreateRunspace())
              {
                  runspace.Open();
                  PowerShell ps = PowerShell.Create();
                  ps.Runspace = runspace;
                  PSSnapInException psex;
                  runspace.RunspaceConfiguration.AddPSSnapIn("McliPSSnapIn", out psex);
  
                  Pipeline pipeline = runspace.CreatePipeline();
  
                  Command mcliAdd = new Command("mcli-add");
                  mcliAdd.Parameters.Add(null, "DiskLocator");
                  mcliAdd.Parameters.Add("-r", "diskLocatorName=" + diskLocatorName + ", " + "siteName=" + siteName + ", " + "storeName=" + storeName);
                  //mcliAdd.Parameters.Add("siteName=" + siteName + ", ");
                  //mcliAdd.Parameters.Add("storeName=" + storeName);
                  pipeline.Commands.Add(mcliAdd);
                  Collection&lt;PSObject&gt; output = pipeline.Invoke();
                  foreach (PSObject x in output)
                  {
                      log.WriteEntry(x.ToString(), EventLogEntryType.Information);
                  }
              }
  </code></pre>
  
  <p>Errors I have gotten with the commented lines uncommented are like this:</p>
  
  <p>A parameter cannot be found that matches parameter name 'siteName=mysite'</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Even weirder is this, I can put this line here any way I want it after the comma and it won't throw an error:</p>
  
  <pre><code>mcliAdd.Parameters.Add("r", "who cares what I put here nothing happens");
  </code></pre>
  
  <p>This leads me to believe that the DiskLocator argument isn't being used right. I can't use it as a parameter because it says that's not a parameter name. </p>
  
  <p>However this can't be true because if I remove it or the -r it either says DiskLocator is missing or that -r is missing. If I pass only -r without the other details it throws an error complaining that there's no string[] array values. So I'm at a loss here. It SHOULD throw an error if I don't provide the entire array, but it's not even throwing an error when I pass just the disklocatorname part.</p>