I'm using this as a reference: http://msdn.microsoft.com/en-us/library/dd182449(v=VS.85).aspx
So the implementation is very similar. I'm executing the following PowerShell command to retrieve process information from the intended computer through the 1-liner command below:
$computer = "Remote.Computer.Here"; Get-Process -computer $computer | Sort-Object WorkingSet -desc | Select-Object -first 10 | Format-Table -property name, ID, @{Expression= {$_.WorkingSet/1mb};Label="MemoryLoad";} -auto
The command above executes perfectly in PS window. However, when called from C# app code, I get no returns. Especially so, when I access it through the following:
PowerShell shell = PowerShell.Create();
shell.AddScript(CmdletMap[PSVocab.OsProcLoad]);
Collection<PSObject> obj = shell.Invoke();
DataTable dt = new DataTable();
dt.Columns.Add("ProcessName");
dt.Columns.Add("ID");
dt.Columns.Add("MemoryLoad");
DataRow row;
foreach (PSObject resultObject in obj)
{
row = dt.NewRow();
row["ProcessName"] = resultObject.Members["name"].Value;
row["ID"] = resultObject.Members["id"].Value;
row["MemoryCol"] = resultObject.Members["MemoryLoad"].Value;
dt.Rows.Add(row);
}
Doing a quick-watch of resultObject.Members[].Value would simply return null.
Any help?
Thanks.