You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Getting error while running Powershell on Linux #16787
I am experiencing an issue while running Powershell 7.0 on my Rhel Docker image.
I installed every required resources like,
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.
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.
@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).
Activity
kasini3000 commentedon Jan 22, 2022
from linux ,use omi ,to win, i have similar question. #16623
mark,the problem may not be resolved soon
jborean93 commentedon Jan 22, 2022
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
22meaning invalid argument. Looking further back this function is called withUTF-16LEandUTF-8. It seems likeiconv_opendoes 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
If either of those 2 calls to
iconv_openfail it will display the errorno and message, in your case it will most likely be22 - Invalid argument. I cannot replicate this at all even on a blankcentos:8container (both return valid pointers) so not sure what's actually happening on your host. One thing to check is the contents of/usr/lib64/gconvto see what it contains. I can seeUNICODE.so,UTF-16.soin 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-providervery much so if the same error is occurring with my fork you will most like still see this error.PaulHigin commentedon Apr 7, 2022
@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).