Skip to content

Register-PSSessionConfiguration throws error when running in PS Core on Windows desktop #2555

@daxian-dbw

Description

@daxian-dbw

This issue is mostly due to the fact that windows desktop has powershell workflow remote endpoint PSSessionConfiguration by default. PowerShell workflow is not supported in PS Core, and thus processing the workflow endpoint causes this issue.

This issue is related to #1798, and they may have the same root cause.

Steps to reproduce

$sessionConfigurationDll = [IO.Path]::Combine([IO.Path]::GetTempPath(), "ImplicitRemotingRestrictedConfiguration$(Get-Random).dll")
Add-Type -OutputAssembly $sessionConfigurationDll -TypeDefinition @"

using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Remoting;

namespace MySessionConfiguration
{
    public class MySessionConfiguration : PSSessionConfiguration
    {
        public override InitialSessionState GetInitialSessionState(PSSenderInfo senderInfo)
        {
            //System.Diagnostics.Debugger.Launch();
            //System.Diagnostics.Debugger.Break();

            InitialSessionState iss = InitialSessionState.CreateRestricted(System.Management.Automation.SessionCapabilities.RemoteServer);

            // add Out-String for testing stuff
            iss.Commands["Out-String"][0].Visibility = SessionStateEntryVisibility.Public;

            // remove all commands that are not public
            List<string> commandsToRemove = new List<string>();
            foreach (SessionStateCommandEntry entry in iss.Commands)
            {
                List<SessionStateCommandEntry> sameNameEntries = new List<SessionStateCommandEntry>(iss.Commands[entry.Name]);
                if (!sameNameEntries.Exists(delegate(SessionStateCommandEntry e) { return e.Visibility == SessionStateEntryVisibility.Public; }))
                {
                    commandsToRemove.Add(entry.Name);
                }
            }

            foreach (string commandToRemove in commandsToRemove)
            {
                iss.Commands.Remove(commandToRemove, null /* all types */);
            }

            return iss;
        }
    }
}
"@

Get-PSSessionConfiguration ImplicitRemotingRestrictedConfiguration* | Unregister-PSSessionConfiguration -Force

$myConfiguration = Register-PSSessionConfiguration `
    -Name ImplicitRemotingRestrictedConfiguration `
    -ApplicationBase (Split-Path $sessionConfigurationDll) `
    -AssemblyName (Split-Path $sessionConfigurationDll -Leaf) `
    -ConfigurationTypeName "MySessionConfiguration.MySessionConfiguration" `
    -Force

Expected behavior

Register-PSSessionConfiguration runs successfully

Actual behavior

Exception calling "Load" with "1" argument(s): "Could not load file or assembly
'Microsoft.Powershell.Workflow.ServiceCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The
system cannot find the file specified."
At line:33 char:9
+         $serviceCore = [Reflection.Assembly]::Load("Microsoft.Powersh ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

Environment data

> $PSVersionTable
PS C:\> $PSVersionTable

Name                           Value
----                           -----
GitCommitId                    v6.0.0-alpha.11-51-ga0dbd11bc2fdd5f4b090b534043f582325535b2a-dirty
PSVersion                      6.0.0-alpha
CLRVersion
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.3
BuildVersion                   3.0.0.0
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions