I've added in the reference to the Powershell dll (C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll); I've also removed that reference and opened up the Project File and added in <Reference Include="System.Management.Automation />
. However, neither of these work, I always get the following error:
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace Powershell_Execution
{
class Program
{
static void Main(string[] args)
{
foreach (String str in PowerShell.Create().AddScript("Get-Process").AddCommand("Out-String").Invoke<String>())
{
Console.WriteLine(str);
}
Console.ReadLine();
}
}
}
Any ideas? Everything I've run across just said to add the <Reference Include="System.Management.Automation />
, but that just produces the same runtime error.
User contributions licensed under CC BY-SA 3.0