Created
December 25, 2012 20:53
-
-
Save dfinke/4375339 to your computer and use it in GitHub Desktop.
Invokes PowerShell from node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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