I am using .NET Core to write some automation with Powershell, I installed the following nugets:
Microsoft.PowerShell.Commands.Management
Microsoft.PowerShell.SDK
Microsoft.WSMan.Management
System.Management.Automation
and is using the following code:
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("$service = Get-CimInstance -ClassName Win32_Service -Filter \"name = 'MyNewService\'\"");
pipeline.Commands.AddScript("$service.DisplayName");
Getting the following Error
System.Management.Automation.CommandNotFoundException: 'The term 'Get-CimInstance' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.'
Any Ideas how to fix the problem, so it will recognize the command?