Skip to content

Automation via .NET Core #7333

@danielman111

Description

@danielman111

Hi All. 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 it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions