Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created December 25, 2012 20:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dfinke/4375339 to your computer and use it in GitHub Desktop.
Save dfinke/4375339 to your computer and use it in GitHub Desktop.
Invokes PowerShell from node
function Invoke-NodeJS {
param(
$PowerShellCommand,
[Switch]$ReturnAsJSON
)
if($ReturnAsJSON) {$PowerShellCommand += " | ConvertTo-Json"}
$tmp = [IO.Path]::GetTempFileName()
@"
var target = 'powershell "$PowerShellCommand"'
require('child_process').exec(target, function(err, sysout) { console.log(sysout); });
"@ | Set-Content $tmp
node $tmp
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
}
Invoke-NodeJS -ReturnAsJSON "ps | ? handles -gt 1100 | select name, cpu, handles"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment