Welcome!

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

SignUp Now!

CsScript .NET plugin release 2026.4 Build 9

Aug
2,799
144
What's New:
A .csx file that can run the TCC PShell command,
allowing me to have access to PowerShell 5.1 from a .csx file.

NOTE WELL: Build 23 of TCC v36 is required to run a TCC command/alias and such from a .csx file using the CsScript plugin.
Rex added the ability for .NET plugins to call TCC commands starting in Build 23.

Ref: News - Take Command v36 Public Beta Build 23 Uploaded

In the included template.csx file,
I have commented out the following;
Code:
                        // Uncomment and change path to test with your own .ps1 file:
                        // Console.WriteLine("TCC PShell script.ps1: " + CsScriptPlugin.CsScript.TccRun("PSHELL \"e:\\utils\\WinVer.ps1\"").TrimEnd());
Please use your own .ps1 file for testing.

But wait, there's more!

You can also,
from tempalte.csx,
call an existing TCC alias.
Code:
R:\>which average
average is an alias : echo %@average[%$]

R:\>which @average
@average is an internal variable

R:\>average 1900 1920 1940 1960 1980
1940

R:\>CsScript template.csx
TCC average: 1940

Here are lines 101 to 108, showing how this is coded in template.csx,
Code:
                        // Example 8: Call TCC commands via TccRun
                        Console.WriteLine("\nTCC PShell get-date: " + CsScriptPlugin.CsScript.TccRun("PSHELL /S \"get-date\"").TrimEnd());
                        Console.WriteLine("TCC PShell 2026-1960: " + CsScriptPlugin.CsScript.TccRun("PSHELL /S \"2026-1960\"").TrimEnd());
                        Console.WriteLine("TCC aliasf: " + CsScriptPlugin.CsScript.TccRun("aliasf").TrimEnd());
                        Console.WriteLine("TCC average: " + CsScriptPlugin.CsScript.TccRun("average 1900 1920 1940 1960 1980").TrimEnd());

                        // Uncomment and change path to test with your own .ps1 file:
                        // Console.WriteLine("TCC PShell script.ps1: " + CsScriptPlugin.CsScript.TccRun("PSHELL \"e:\\utils\\WinVer.ps1\"").TrimEnd());

Note that I am running aliasf from the .csx file.

If aliasf does not exist in your TCC, the following will be displayed;
Code:
TCC PShell get-date: April 9, 2026 3:59:47 PM
TCC PShell 2026-1960: 66
Error: Exception has been thrown by the target of an invocation.

Thus, the .csx script stops running,
and the remainder of the script will not be processed.

The attached CsScript.zip file contains;
Code:
R:\>zip /v CsScript.zip
2026-04-09  19:18          9,728   55%  CsScript.dll
2026-04-09  19:32          5,276   74%  template.csx

At present,
output is displayed to the terminal,
and cannot be captured to the clipboard, etc.

That is;
Code:
csscript template.csx > clip:
...will not result in output being re-directed to the Windows clipboard.

One of many things to-do,
but for now,
I just want others to test and make sure what I have done so far works on your system.

Thanks from Joe
 

Attachments

Last edited:
Back
Top