Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Unable to use PShell v36 to create a PowerShell alias

Aug
2,799
144
What used to work in v35, but does not work in v36.

Note that,
in v36,
after defining the alias,
there is an extra blank line displayed.

This is not the case in v35.

Joe

Code:
TCC  35.00.21 x64   Windows 10 [Version 10.0.19045.7058]

E:\Utils>pshell /s "New-Alias -Name test -value 'C:\cygwin64\bin\cal.exe'"

E:\Utils>pshell /s "get-content alias:test"
C:\cygwin64\bin\cal.exe

Code:
TCC  36.00.17 x64   Windows 10 [Version 10.0.19045.7058]

E:\Utils>pshell /s "New-Alias -Name test -value 'C:\cygwin64\bin\cal.exe'"


E:\Utils>pshell /s "get-content alias:test"
PSHELL: Cannot find path 'Alias:\test' because it does not exist.

Addendum: v36 will not load the PowerShell $Profile.

As v36 PShell cannot create PowerShell functions and aliases,
the PowerShell $Profile may be loading,
but it would appear that none of the functions and aliases that I have defined in my PowerShell $Profile are being created.
 
While I was debugging this, I discovered that doing a "get-content alias:test" when the alias wasn't defined caused .NET to throw a (managed) exception which caused TCC.EXE to abort. I couldn't figure out how to handle the exception (which was interacting badly with the C++ and the SEH exception handlers), so I tried asking Claude 4.6 and GPT 5.4.

Claude made a dozen suggestions and code changes, none of which worked. It eventually suffered a mental breakdown, crashed CoPilot and necessitated restarting Visual Studio.

GPT made a dozen suggestions and code changes, none of which worked. It eventually gave up and suggested that I run Powershell directly rather than trying to access it from another app.
 
Yes, I have found that using;
Code:
PS E:\utils> if (-not (Test-Path function:abc)) {Write-Output Nope!}
Nope!

...or...

Code:
PS E:\utils> if (Test-Path function:abc) {get-content function:abc}
PS E:\utils> if (Test-Path function:v) {get-content function:v}

  & 'C:\Program Files\V64\v.exe' @args

PS E:\utils>
prevents that issue.

Joe
 
Making MyPshell persistent was one thing that I could never figure out how to do.

Joe
 
GPT made a dozen suggestions and code changes, none of which worked. It eventually gave up and suggested that I run Powershell directly rather than trying to access it from another app.
That's why I have been looking at alternate solutions.

Using PowerShell from TCC without a 3rd-Party DLL

The bonus of using this method,
is that it works with PowerShell 7.x,
as well as PowerShell 5.1

Still some issues with it,
but it does provide a persistent PowerShell from TCC.

Joe
 
Fixewd in build 18. (It was setting the alias in a child process, so it was being lost when returning to the parent process.)
Still the same in build 18.

Code:
R:\>pshell /s "New-Alias -Name test -value 'C:\cygwin64\bin\cal.exe'"

R:\>pshell /s "get-content alias:test"
PSHELL: Cannot find path 'Alias:\test' because it does not exist.

R:\>ver

TCC  36.00.18 x64   Windows 10 [Version 10.0.19045.7058]

Joe
 
Fixed in Buld 19.

Code:
R:\>pshell /s "New-Alias -Name test -value 'C:\cygwin64\bin\cal.exe'"

R:\>pshell /s "get-content alias:test"
C:\cygwin64\bin\cal.exe

R:\>pshell /s "test"
     April 2026
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30


R:\>ver

TCC  36.00.19 x64   Windows 10 [Version 10.0.19045.7058]
 
As v36 PShell cannot create PowerShell functions and aliases,
the PowerShell $Profile may be loading,
but it would appear that none of the functions and aliases that I have defined in my PowerShell $Profile are being created.

Thankyou Rex.

As of Build 19,
no more errors from TCStart.btm,
or from my Aliases that use PShell,
as the functions and aliases that I have defined in my PowerShell $Profile are now being created as they were in version 35.

Joe
 
Back
Top