Skip to content

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

Closed

Description

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

Activity

  1. daxian-dbw commented on Oct 29, 2016

    @daxian-dbw
    MemberAuthor

    The implicit remoting tests "Implicit remoting on restricted ISS" are skipped due to this bug. So for whoever works on this bug, please update the tests accordingly when you resolve this bug.

  2. added this to the milestone on Nov 4, 2016
  3. changed the title [-]Register-PSSessionConfiguration throws error when running in PS Core on windows desktop[/-] [+]Register-PSSessionConfiguration throws error when running in PS Core on Windows desktop[/+] on May 22, 2017
  4. joeyaiello commented on May 22, 2017

    @joeyaiello
    Contributor

    Per conversation with Hemant Mahawar (@HemantMahawar) and Steve Lee (@SteveL-MSFT), anyone using GetInitialSessionState to create restricted endpoints is broken (including Exchange). Leaving in 6.0.0 for now (especially if we decide to ship GetInitialSessionState in "PowerShell Standard" /cc Jason Shirk (@lzybkr)).

  5. modified the milestones: , on May 22, 2017
  6. joeyaiello commented on Sep 19, 2017

    @joeyaiello
    Contributor

    This doesn't repro anymore in Beta.7 (possibly earlier):

    $myConfiguration
    
    
       WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Plugin
    
    Type            Keys                                Name
    ----            ----                                ----
    Container       {Name=ImplicitRemotingRestricted... ImplicitRemotingRestrictedConfiguration
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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