PSHELL in v27 vs. 26

Code:
     _x64: 1
   _admin: 1
_elevated: 1

TCC  27.00.18 x64   Windows 10 [Version 10.0.18363.1256]

In v26, I see my PowerShell Profile;
Code:
e:\utils>pshell /s "$profile"
e:\Documents\WindowsPowershell\Microsoft.PowerShell_profile.ps1

In v27, I see my PowerShell Profile;
Code:
e:\utils>pshell /s "$Profile"
e:\Documents\WindowsPowershell\Microsoft.PowerShell_profile.ps1

In my $Profile, I have many UDFs, such as CreateObject.

In v26, this works;
Code:
e:\utils>pshell /s "$jlc = CreateObject('jlcutils.clsMath')"

e:\utils>pshell /s "$jlc | get-member"


   TypeName: System.__ComObject#{fdd19134-ea6a-43c0-90aa-00cc2ff3989a}

Name   MemberType Definition
----   ---------- ----------
ppp    Method     Variant ppp (Variant)
vb6Val Method     double vb6Val (string)
World  Method     Variant World (string)

In v27, it does not work;
Code:
e:\utils>pshell /s "$jlc = CreateObject('jlcutils.clsMath')"
PSHELL: System.Management.Automation.CommandNotFoundException : The term 'CreateObject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

In v27, none of my user defined functions from my $Profile work.

What has changed?

From the "What's New In Version 27";
Code:
What's New in Version 27                                
PowerShellProfileID=string - The profile Id to look for when loading profiles. TCC will look for profiles that begin with the specified Id. For instance, the default value is "Microsoft.PowerShell" so the class will look for profiles named "Microsoft.PowerShell_profile.ps1".

Can others who have UDFs in their $Profile see if they work in v27?

Joe
 
In v26, I can reload my PowerShell Profile as follows;
Code:
pshell /s ".$Profile"
and it works.

In v27, I try to reload my PowerShell Profile as follows;
Code:
pshell /s ".$Profile"
PSHELL: System.Management.Automation.ParseException : The "=" operator is missing after a named argument.
and it does not work.

Why?

Joe
 
In v27;
Code:
e:\downloads>pshell /s "get-host"


Name             : PowerShell SSH Components C++ Edition
Version          : 1.0.0.3756
InstanceId       : 6b5832eb-e7be-4dc8-9200-c46b7aa0af27
UI               : System.Management.Automation.Internal.Host.InternalHostUserIn
                   terface
CurrentCulture   : en-CA
CurrentUICulture : en-US
PrivateData      :
IsRunspacePushed :
Runspace         :

In v26
Code:
e:\utils>pshell /s "get-host"


Name             : PowerShell SSH Components C++ Edition
Version          : 1.0.0.3756
InstanceId       : 0ef5d542-4266-4044-9797-85d7155a7be6
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-CA
CurrentUICulture : en-US
PrivateData      :
DebuggerEnabled  : True
IsRunspacePushed :
Runspace         :

Why does v26 have the
Code:
DebuggerEnabled  : True
but v27 does not?

Joe
 
In v26
Code:
e:\utils>pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  610

In v27
Code:
e:\utils>pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

Show different versions of Powershell. This would explain why the majority of my functions no longer work in v27.

@rconn why is v27 using an older version of Powershell than v26?

Joe
 
Yep, that's the same error I get with v27 when attempting to use PSHELL.

That error is due to PowerShell version 2, which was deprecated in August 2017.
Code:
e:\utils>powershell.exe -version 2
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

) : The "=" operator is missing after a named argument.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingEqualsInNamedArgument

Joe
 

rconn

Administrator
Staff member
May 14, 2008
12,161
140
In v26
Code:
e:\utils>pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  610

In v27
Code:
e:\utils>pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

Show different versions of Powershell. This would explain why the majority of my functions no longer work in v27.

@rconn why is v27 using an older version of Powershell than v26?

Joe

The only difference between v26 & v27 is the optional profile ID. The rest of the TCC code & the Powershell support dll (NSILP_PowerShell.x64.dll) are identical.
 
May 20, 2008
11,019
88
Syracuse, NY, USA
V26 is loads these DLLs:
Code:
C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\Microsoft.P1706cafe#\48cda96df563d31028542f0859ef1adc\Microsoft.PowerShell.Commands.Diagnostics.ni.dll
C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\Microsoft.Pb378ec07#\882818c534d0020bdc80236ecc332d62\Microsoft.PowerShell.ConsoleHost.ni.dll
C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\Microsoft.P521220ea#\e80a80431c4364861d8e69efe5506c9c\Microsoft.PowerShell.Commands.Utility.ni.dll
C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\Microsoft.Pae3498d9#\fad8d2a4b892e19ffc6c121886ff3420\Microsoft.PowerShell.Commands.Management.ni.dll
C:\WINDOWS\assembly\NativeImages_v4.0.30319_64\Microsoft.P6f792626#\4336bb800ae79661d8dd662df521693d\Microsoft.PowerShell.Security.ni.dll

And v27 loads these.
Code:
C:\WINDOWS\assembly\NativeImages_v2.0.50727_64\Microsoft.PowerShel#\b8c5c8afd16e6ebfeea638b3046ebdcb\Microsoft.PowerShell.Commands.Diagnostics.ni.dll
C:\WINDOWS\assembly\NativeImages_v2.0.50727_64\Microsoft.PowerShel#\d6f6ab091c8f2d8535094e5306fcc724\Microsoft.PowerShell.Commands.Utility.ni.dll
C:\WINDOWS\assembly\NativeImages_v2.0.50727_64\Microsoft.PowerShel#\6f4baa52e3c82e2f9cb7e7f5bbdf99f6\Microsoft.PowerShell.ConsoleHost.ni.dll
C:\WINDOWS\assembly\NativeImages_v2.0.50727_64\Microsoft.PowerShel#\1366fecd56481ba6fd38aced8458af8b\Microsoft.PowerShell.Commands.Management.ni.dll
C:\WINDOWS\assembly\NativeImages_v2.0.50727_64\Microsoft.PowerShel#\80d3d258bf9bcd18e934da4e934af084\Microsoft.PowerShell.Security.ni.dll
 
May 20, 2008
11,019
88
Syracuse, NY, USA
Apparently I can run either one.
Code:
v:\> powershell.exe -version 2
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.


V:\> exit

v:\> powershell.exe -version 5
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6
 
May 20, 2008
11,019
88
Syracuse, NY, USA
I thought perhaps this would help (in an elevated PowerShell).

Code:
Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root

But after that v27's PSHELL did nothing at all. I reversed that with this.

Code:
Enable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root
 
The only difference between v26 & v27 is the optional profile ID. The rest of the TCC code & the Powershell support dll (NSILP_PowerShell.x64.dll) are identical.
Well @rconn it would appear that @vefatica has found the difference.

Joe
 
May 20, 2008
11,019
88
Syracuse, NY, USA
Those DLLs don't seem to be the same (it's odd that they have the same timestamp). And when I replace the v27 one with the v26 one, PSHELL in v27 works better.

Code:
d:\tc27> d ns*
2019-02-06  12:03          56,528  NSILP_PowerShell.x64.dll

d:\tc27> d ..\tc26\ns*
2019-02-06  12:03          61,136  NSILP_PowerShell.x64.dll

d:\tc27> ren NSILP_PowerShell.x64.dll NSILP_PowerShell.x64.dll.bak
D:\tc27\NSILP_PowerShell.x64.dll -> D:\tc27\NSILP_PowerShell.x64.dll.bak
     1 file renamed

d:\tc27> copy ..\tc26\NSILP_PowerShell.x64.dll
D:\tc26\NSILP_PowerShell.x64.dll => D:\tc27\NSILP_PowerShell.x64.dll
     1 file copied

d:\tc27> pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  610

d:\tc27> ver
TCC 27.00.18 x64
Microsoft Windows 10 Pro for Workstations
10.0.19042.746 (2009, 20H2)
 
Those DLLs don't seem to be the same (it's odd that they have the same timestamp). And when I replace the v27 one with the v26 one, PSHELL in v27 works better.

Code:
d:\tc27> d ns*
2019-02-06  12:03          56,528  NSILP_PowerShell.x64.dll

d:\tc27> d ..\tc26\ns*
2019-02-06  12:03          61,136  NSILP_PowerShell.x64.dll

d:\tc27> ren NSILP_PowerShell.x64.dll NSILP_PowerShell.x64.dll.bak
D:\tc27\NSILP_PowerShell.x64.dll -> D:\tc27\NSILP_PowerShell.x64.dll.bak
     1 file renamed

d:\tc27> copy ..\tc26\NSILP_PowerShell.x64.dll
D:\tc26\NSILP_PowerShell.x64.dll => D:\tc27\NSILP_PowerShell.x64.dll
     1 file copied

d:\tc27> pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  610

d:\tc27> ver
TCC 27.00.18 x64
Microsoft Windows 10 Pro for Workstations
10.0.19042.746 (2009, 20H2)
Thankyou @vefatica!

All I had to do was copy the NSILP_PowerShell.x64.dll from v26 to v27.

I can now use the PS5 version of PSHELL again!
Code:
e:\utils>pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  610



e:\utils>whatver
     _x64: 1
   _admin: 1
_elevated: 1

TCC  27.00.18 x64   Windows 10 [Version 10.0.19042.746]
BuildNumber  Caption                   CSDVersion  OSArchitecture  Version
19042        Microsoft Windows 10 Pro              64-bit          10.0.19042

Joe
 
Those DLLs don't seem to be the same (it's odd that they have the same timestamp). And when I replace the v27 one with the v26 one, PSHELL in v27 works better.

Code:
d:\tc27> d ns*
2019-02-06  12:03          56,528  NSILP_PowerShell.x64.dll

d:\tc27> d ..\tc26\ns*
2019-02-06  12:03          61,136  NSILP_PowerShell.x64.dll

d:\tc27> ren NSILP_PowerShell.x64.dll NSILP_PowerShell.x64.dll.bak
D:\tc27\NSILP_PowerShell.x64.dll -> D:\tc27\NSILP_PowerShell.x64.dll.bak
     1 file renamed

d:\tc27> copy ..\tc26\NSILP_PowerShell.x64.dll
D:\tc26\NSILP_PowerShell.x64.dll => D:\tc27\NSILP_PowerShell.x64.dll
     1 file copied

d:\tc27> pshell /s "$PSVersionTable.PSVersion"

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  610

d:\tc27> ver
TCC 27.00.18 x64
Microsoft Windows 10 Pro for Workstations
10.0.19042.746 (2009, 20H2)
Using dumpbin.exe /all I can see several differences between the two DLL files.

Joe
 
May 20, 2008
11,019
88
Syracuse, NY, USA
It could have something to do with CLR (about which I know next to nothing). Using PSHELL in v26 causes these DLLs to be loaded.
Code:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll   
C:\WINDOWS\SYSTEM32\VCRUNTIME140_CLR0400.dll              
C:\WINDOWS\SYSTEM32\ucrtbase_clr0400.dll                  
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clrjit.dll[code]

With v27 and the v27 NSILP_PowerShell.x64.dll, neither those, nor any with similar names, are loaded.  The first few paragraphs in [URL='https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-the-windows-powershell-2.0-engine?view=powershell-7.1']this[/URL] article talk about the relationship between PowerShell engine versions and CLR.
 
May 20, 2008
11,019
88
Syracuse, NY, USA
Sure enough ...

With the v27 DLL,

Code:
d:\tc27> clrver %_pid

Microsoft (R) .NET CLR Version Tool  Version 4.8.3928.0
Copyright (c) Microsoft Corporation.  All rights reserved.

v2.0.50727

With the v26 DLL,

Code:
d:\tc27> clrver %_pid

Microsoft (R) .NET CLR Version Tool  Version 4.8.3928.0
Copyright (c) Microsoft Corporation.  All rights reserved.

v4.0.30319
 
Thread starter Similar threads Forum Replies Date
Joe Caverly Support 1
V Support 5
Peter Murschall Support 8
Joe Caverly Support 2
V Support 15