0

I have a small node.js app from which I wish to send array of objects to a function in powershell script and manipulate it there. I'm using node-powershell library for this purpose. But the problem is I'm not able to catch the Array of objects as parameter in powershell function, it's giving unexpected error.

    app.get('/preview-rule', async (req, res) => {
    let ps = new Shell({
        executionPolicy: 'Bypass',
        noProfile: true
    });

    let rules = [{
        path: "amer/arbue/legacy",
        ldapFilter: "(&(sAMAccount=*k))"
    }, {
        path: "",
        ldapFilter: "(&(l=u*))"
    }];

    ps.addCommand('. ./Scripts/PSScript1.ps1')
    ps.addCommand('PreviewRule')
    ps.addParameter({ rules: JSON.stringify(rules) })
    ps.invoke()
        .then(output => {
            console.log(output);
            res.status(200).send('success!');
        })
        .catch(err => {
            console.log(err);
            ps.dispose();
        });
});

error_message

malarres
  • 2,941
  • 1
  • 21
  • 35
  • 2
    Welcome to SO :-) What have you tried so far? https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js looks like a nice way to start, and if you don't have any restrictions on that, one of the easiest ways to communicate between different binaries is via files – malarres Jun 25 '20 at 05:41
  • Welcome to stackoverflow, Aarish! I hope you find the community here helpful :). If I may suggest, it will make it easier for people to answer your question if you add to it code that shows how you're currently using node-powershell as well as the text of the error message you're getting. Good luck! – urig Jun 25 '20 at 06:19
  • I've included the code snippet and the error message above. Please have a look. – Aarish Rahman Jun 25 '20 at 06:29
  • It looks like you're dot sourcing a file and then executing a function named PreviewRule, which was hopefully declared in the file with a single parameter. (It would have been helpful to post that too.) Likely your issue was that you weren't quoting the JSON. – Robb Vandaveer Aug 26 '20 at 17:43

0 Answers0