Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

438
Visualizações
node-powershell - getting output back into javascript

I'm trying to be able to interact with powershell using node-powershell.

Powershell output is typically a dataframe type object you can store in a variable. I'm just not clear on how to get the output back into JS to store/display it.

I think I need to be able to read the stdout but I'm not sure how to do this and keep the data in a formatted way.I'd like the data returned in an object.

In my code, im getting a pending promise back, i don't understand why.

const { PowerShell } = require('node-powershell')

const poshInstance = async () => {
    const ps = new PowerShell({
        executionPolicy: 'Bypass',
        noProfile: true,
    })

    const command = PowerShell.command`Get-LocalGroup`
    const output = await ps.invoke(command)
    //const output = await PowerShell.$`Get-LocalGroup`
    ps.dispose()
  const stringFromBytes = String.fromCharCode(...output.stdout)
    // console.log(stringFromBytes)
  return JSON.stringify(stringFromBytes)
}


const op = poshInstance()

console.log(op)


about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This library seams to return raw text output of the command. To create objects from this the simplest solution is to serialize the result to JSON format inside powershell session. Then you just have to parse the output.

const { PowerShell } = require('node-powershell')

const poshInstance = async () => {
    const ps = new PowerShell({
        executionPolicy: 'Bypass',
        noProfile: true
    })

    const command = PowerShell.command`Get-LocalGroup | ConvertTo-Json`
    const output = await ps.invoke(command)
    ps.dispose()
    console.log(output)
    const result = JSON.parse(output.raw)
    console.log(result)
}

(async () => 
{
    await poshInstance()
})();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda