0
script += string.Format(@"$Processes = Get-Process -ComputerName {0} | Sort-Object CPU -desc | Select-Object;", remoteMachineName);
script += @"$ProcessArray= @();";
script += @"foreach ($process in $Processes) {";
script += @"$ProcessNamesss = $process.ProcessName;";
script += @"$objAverage = New-Object System.Object;";
script += @"$objAverage | Add-Member -type NoteProperty -name Name -value $ProcessNamesss;";
script += @"$ProcessArray +=$objAverage; } ";
script += "$ProcessArray;";

My code runs fine. but it returns 109 results. It should return one result with array that contains 109 objects? which i have filled in foreach loop? How can i return only that array $ProcessArray?

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Waqar Ahmed
  • 1,414
  • 2
  • 15
  • 35

0 Answers0