Skip to content

Instantly share code, notes, and snippets.

@cat2151
Created July 20, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cat2151/48c1bb91558369815f6ddc06177380df to your computer and use it in GitHub Desktop.
Save cat2151/48c1bb91558369815f6ddc06177380df to your computer and use it in GitHub Desktop.
batファイル内のPowerShell内のJScript.NET(≒JavaScript)プログラムを動かす
@powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 1})-join\"`n\");&$s" %*&goto:eof
# http://qiita.com/cd01/items/82829ba0ec0f59e1b04d
# http://winscript.jp/powershell/221
Param($argBat)
$src = @'
static function helloFunc(arg) {
var msg = "hello " + arg + " world";
Console.WriteLine(msg);
return msg;
}
'@
$JScNet = (Add-Type -Language JScript -MemberDefinition $src -Name "JScNet" -PassThru)[1]
$helloResult = $JScNet::helloFunc($argBat)
Write-Output -InputObject $helloResult
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment