I have library built for .NET Standard 2.0.
I am using this library in
- a .NET Core project and
- a .NET Framework project.
I have integrated this PowerShellStandard.Library (Version 5.1.0) nuget into my .NET Standard library. It is used to fetch some date which is connected to PC.
private string RunPowerShellCommand(string paramValue)
{
using (PowerShell powershell = PowerShell.Create().AddCommand("Get-PnpDeviceProperty").AddParameter("InstanceId", paramValue).AddParameter("KeyName", "DEVPKEY_Device_Parent"))
{
var result = powershell.Invoke();
string deviceId = "";
foreach (var r in result)
{
var properties = r.Properties;
var device = (string)properties.Where(t => t.Name == "Data").FirstOrDefault().Value;
deviceId = (string)device;
}
return deviceId.Split('\\')[2];
}
}
- When I call above code from the .NET Framework project then the
PowerShell.Create()returns the proper PowerShell object - When I call same code from the .NET Core project then it returns
null.
Could anyone me please ?!
Enable same Module to support PowerShell Core and Windows PowerShell, not that you can load Windows PowerShell into a .NET Core applicatinopowershell.HadErrorsand the contents ofpowershell.Streams.Errortell you? :)