Skip to content

Getting error while running Powershell on Linux #16787

Closed

Description

@Parshyaa

Prerequisites

Steps to reproduce

I am experiencing an issue while running Powershell 7.0 on my Rhel Docker image.
I installed every required resources like,

  1. https://github.com/powershell/powershell
    From this link I have downloaded powershell-7.2.1-rhel.x.x86_64.rpm. The main Powershell core rpm package bundle for linux.
    This seams to work, as I am able to run Pwsh on my RHEL image.
  2. Installed https://github.com/Microsoft/omi/releases/tag/v1.6.0 for connecting to my Windows Exchange server for running powershell on remote server from RHEL to Windowes.
    3)https://github.com/PowerShell/psl-omi-provider

but when I run the New-PSSession in the PWSH, I get this error,

PS /> New-PSSession
Failed to create iconv, 22
New-PSSession:
PS />

I searched on internet got none of the solution working.

Please if you have any information so that I would be able to run this on my RHEL server.

Expected behavior

To create a PSSession

Actual behavior

Gets error, 
Failed to create iconv, 22

Error details

Failed to create iconv, 22

Environment data

PS /> $psversiontable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Linux 4.4.115-boot2docker #1 SMP Thu Feb 8 17:36:45 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. added
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Jan 21, 2022
  2. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    WG-RemotingPSRP issues with any transport layer
    on Jan 21, 2022
  3. kasini3000 commented on Jan 22, 2022

    @kasini3000

    from linux ,use omi ,to win, i have similar question. #16623
    mark,the problem may not be resolved soon

  4. jborean93 commented on Jan 22, 2022

    @jborean93
    Collaborator

    This error comes from psl-omi-provider at https://github.com/PowerShell/psl-omi-provider/blob/59ab42f3bc769b1aa31c1181e3a97ea3e1b1c96e/src/BufferManipulation.c#L35-L39. It would indicate there's a problem calling iconv_open and the error code it's returning is 22 meaning invalid argument. Looking further back this function is called with UTF-16LE and UTF-8. It seems like iconv_open does not support either of these character sets or maybe the combination of both for your setup.

    You can replicate this same call in pwsh with

    Add-Type -Namespace Native -Name Methods -MemberDefinition @'
    [DllImport("libc", SetLastError = true)]
    private static extern IntPtr iconv_open(string tocode, string fromcode);
    
    public static IntPtr IconvOpen(string to, string from)
    {
        IntPtr res = iconv_open(to, from);
        if (res == new IntPtr(-1))
        {
            var ex = new System.ComponentModel.Win32Exception();
            
            throw new Exception(String.Format("iconv_open error {0} - {1}", ex.NativeErrorCode, ex.Message));
        }
        
        return res;
    }
    '@
    
    [Native.Methods]::IconvOpen("UTF-16LE", "UTF-8")
    [Native.Methods]::IconvOpen("UTF-8", "UTF-16LE2")

    If either of those 2 calls to iconv_open fail it will display the errorno and message, in your case it will most likely be 22 - Invalid argument. I cannot replicate this at all even on a blank centos:8 container (both return valid pointers) so not sure what's actually happening on your host. One thing to check is the contents of /usr/lib64/gconv to see what it contains. I can see UNICODE.so, UTF-16.so in that folder. Unfortunately at this point I don't fully understand the behaviour of iconv but the problem for this particular issue lies there and that's where you should investigate further.

    Just as a side note, the fact that this function is being reached is usually an indication that the underlying MI library failed for some reason and it is trying to convert the error code from UTF-16-LE encoded bytes to UTF-8 for consumption. There are numerous issues with MI on Linux and the provided one from pwsh is mostly a best effort attempt but not really that great. You could try my fork https://github.com/jborean93/omi through the PSWSMan module. This is not supported by MS in any way and is mostly my attempt to solve the various problems MI has on Linux in relation to PowerShell remoting. It also doesn't really change psl-omi-provider very much so if the same error is occurring with my fork you will most like still see this error.

    GitHub
    PSRP Linux support library. Contribute to PowerShell/psl-omi-provider development by creating an account on GitHub.
    GitHub
    Open Management Infrastructure. Contribute to jborean93/omi development by creating an account on GitHub.
  5. PaulHigin commented on Apr 7, 2022

    @PaulHigin
    Contributor

    @WG-Remoting
    New-PSSession is no longer supported on non-Windows platforms, because OMI is no longer supported (#15310). We hope that the community will pick up support for this using the new Custom Remote Connections support (#16923).

  6. ghost removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Apr 7, 2022
  7. added and removed
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Apr 7, 2022
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

    Resolution-AnsweredThe question is answered.WG-RemotingPSRP issues with any transport layer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions