Skip to content

GetProcessCommand not available when trying to Host Powershell Core #8046

@brgr-s

Description

@brgr-s

Preface

Not sure if this is the right place or if my problem is an issue or by design. We are currently looking alternatives for a self developed scripting engine.

Our partners know Powershell, however one of our requirements is independence on any "installed" software, so Windows Powershell, even though it should be available on every Windows 7+, can not be considered.

We are looking at Powershell Core because as far as we understand we should be able to provide everything that is necessary to run a script by simple copy-deployement.

Furthermore, we want to have control over which Cmdlets can be executed ("sandboxing"), so we want to use runspaces and host the powershell scripts ourselves.

I was tryint to setup a simple powershell core host with a runspace using these two examples:

https://github.com/PowerShell/PowerShell/tree/master/docs/host-powershell/sample-dotnet2.0-powershell.beta.3

https://docs.microsoft.com/en-us/powershell/developer/hosting/creating-a-constrained-runspace

In the second link, a runspace is created and the "Get-Process" Cmdlet should be made available by using

SessionStateCmdletEntry ssce1 = new SessionStateCmdletEntry(
                                                            "get-process",
                                                            typeof(GetProcessCommand),
                                                            null);

However, when I use the first link as base, getting the powershell core sdk using nuget, GetProcessCommand is not known. The reasons seems to be that GetProcessCommand is available in Micrososft.Powershell.Commands.Management, however the nutget Package has a "ref" dll (System.Management.Automation) that does not expose GetProcessCommand.

Is this an oversight or by design, maybe because Get-Process is not available on all platforms? Can we work around this problem by refering to Microsoft.Powershell.Commands.Managment assembly directly or are we going down a dangerous path? If this behaviour is intentional, is there a list on which cmdlets implementatios are platform dependant or not immediately available in the Powershell Core SDK?

We are currently not intending to target anything else but Windows.

Steps to reproduce

  1. Use https://github.com/PowerShell/PowerShell/tree/master/docs/host-powershell/sample-dotnet2.0-powershell.beta.3 as base
  2. Try to do
SessionStateCmdletEntry ssce1 = new SessionStateCmdletEntry(
                                                            "get-process",
                                                            typeof(GetProcessCommand),
                                                            null);

Expected behavior

compiles

Actual behavior

does not compile

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0```

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 aWG-DevEx-SDKhosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions