Skip to content

Instantly share code, notes, and snippets.

@kai2nenobu
Created March 23, 2021 02:28
Show Gist options
  • Save kai2nenobu/e5d134e1c9eb7f5eb7948a77df255f71 to your computer and use it in GitHub Desktop.
Save kai2nenobu/e5d134e1c9eb7f5eb7948a77df255f71 to your computer and use it in GitHub Desktop.
JScriptにPowershellスクリプトを埋め込む
function // { # Define a nop function
param($nop)
{ // } > $null
return
}
// <# Call an embedded powershell from JScript
function escape(arg) {
return '"' + arg + '"';
}
var ws = WScript.CreateObject('Wscript.Shell');
var showWindow = 1;
var waitExit = true;
var command = 'powershell -NoProfile -File "' + WScript.ScriptFullName + '"';
for (var i = 0; i < WScript.Arguments.length; i++) {
var arg = WScript.Arguments(i);
WScript.Echo("JScript - " + i + ": " + arg);
command += " " + escape(arg);
}
WScript.Echo(command);
var exitCode = ws.run(command, showWindow, waitExit);
WScript.Quit(exitCode);
/* Start of JScript comment
#>
Remove-Item -Path Function:\// # Remove a nop function
#### Start of powershell script
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
for ($i = 0; $i -lt $Args.Count; $i++) {
Write-Host "Powershell - $($i): $($Args[$i])"
}
Read-Host
#### End of powershell script
# End of JScript comment */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment