3

I migrated from .NET Framework 4.8 to .NET 6.

System.Management.Automation.PowerShell.Create();

now returns null.

Packages

Is there a new package i need to reference or other solution?

mklement0
  • 382,024
  • 64
  • 607
  • 775
rubgra
  • 165
  • 2
  • 9
  • This is happening because of a version of miss-match. Can please share the exception if any – vwadhwa3 Jan 18 '22 at 20:30
  • Nevermind https://stackoverflow.com/questions/51733481/powershell-create-returning-null helped me. – rubgra Jan 18 '22 at 20:34
  • 1
    At a minimum you need [System.Management.Automation](https://www.nuget.org/packages/System.Management.Automation/) (everything contained in that package is also included in the SDK) – Mathias R. Jessen Jan 18 '22 at 20:37

1 Answers1

3

Removing the old References and adding the NuGet package Microsoft.PowerShell.SDK solved this issue.

mklement0
  • 382,024
  • 64
  • 607
  • 775
rubgra
  • 165
  • 2
  • 9
  • 1
    An overview of all PowerShell SDK-related packages can be found in [this answer](https://stackoverflow.com/a/58211901/45375). – mklement0 Jan 18 '22 at 20:40
  • 1
    Note, however, that the package you mention is for creating _stand-alone_ PowerShell (Core) applications, whereas the [`PowerShellStandard.Library`](https://www.nuget.org/packages/PowerShellStandard.Library/) package is for creating modules and PowerShell hosts that run _from within PowerShell_ - and the latter package is designed to work in PowerShell (Core) sessions too. – mklement0 Jan 18 '22 at 20:48
  • 1
    I wasted time trying to use the powershellstandard.library. Because the SDK was so large and I was skeered to use it. This article may help: https://stackoverflow.com/questions/51733481/powershell-create-returning-null – Post Impatica Nov 04 '22 at 21:25