• Ask a Question
  • Create a Poll
150
    Ask a Question
    Cancel
    150
    More answer You can create 5 answer(s).
      Ask a Poll
      Cancel

      Why C# PowerShell.Create() returns null in case of .NET Core?

      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 ?!

      0 Answers