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:
mcli-add DiskLocator -r diskLocatorName=XAShared-2015-10-13, siteName=mysite, storeName=pvs_prod
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.
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 Executing: Add DiskLocator in the event log but I am not seeing the second result which should be Add Succeeded. followed by a result ID:
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<PSObject> output = pipeline.Invoke();
foreach (PSObject x in output)
{
log.WriteEntry(x.ToString(), EventLogEntryType.Information);
}
}
Errors I have gotten with the commented lines uncommented are like this:
A parameter cannot be found that matches parameter name 'siteName=mysite'
UPDATE:
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:
mcliAdd.Parameters.Add("r", "who cares what I put here nothing happens");
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.
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.