Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  114] [ 7]  / answers: 1 / hits: 15167  / 14 Years ago, thu, july 29, 2010, 12:00:00

Reading through the documentation for powershells add-type it seems you can add JScript code to you powershell session.



Firstly is there a decent example of how this is done and secondly can you use this to validate normal javascript code (as I understand JScript is the MS implementation)


More From » powershell

 Answers
78

This may be a good starting point



PowerShell ABC's - J is for JavaScript (by Joe Pruitt)



Here is a code snippet from the above article:



function Create-ScriptEngine()
{
param([string]$language = $null, [string]$code = $null);
if ( $language )
{
$sc = New-Object -ComObject ScriptControl;
$sc.Language = $language;
if ( $code )
{
$sc.AddCode($code);
}
$sc.CodeObject;
}
}
PS> $jscode = @
function jslen(s)
{
return s.length;
}
@
PS> $js = Create-ScriptEngine JScript $jscode;
PS> $str = abcd;
PS> $js.jslen($str);
4

[#96085] Sunday, July 25, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rey

Total Points: 415
Total Questions: 100
Total Answers: 100

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;