Nizue
Contributor
Contributor

A simple way to pass multiple arguments to standalone vRO

Hello, dear forum users!

Please tell me if there is a way to simply pass multiple variables to PowerShell script using "Invoke a PowerShell script" workflow or similar solution. I have succeed with passing one argument :Input variable is person and it works, I'm getting hello world which is addressing me (script is below). But what can I do to pass multiple arguments or maybe even named parameters to PowerShell scripе at the same time, without greatly complicating the code?

var sess;
try {
    sess = host.openSession()
    sess.addCommandFromString("powershell -command 'C:/Users/Administrator/scripts/person.ps1' " + person)
    var invResult = sess.invokePipeline();
    //Show result
    System.log( invResult.getHostOutput() );
     
    //Check for errors
    if (invResult.invocationState  == 'Failed'){
        System.error(invResult.getErrors());
    } else {
        // Get PowerShellRemotePSObject
        System.log();//extract value from result
        }   
    }
finally {
    if (sess) {
        host.closeSession( sess.getSessionId());
    }
}
0 Kudos
1 Reply
emacintosh
Hot Shot
Hot Shot

I think this may be more of a powershell/cmd question...if you are going to launch a script like this, then try using -file instead of -command?

sess.addCommandFromString('powershell -file "C:/Users/Administrator/scripts/person.ps1" person place thing')

 

In general, i would suggest trying to get it working from a command prompt first.  For example, i created a simple script and then opened a command prompt to see if i could get it working using this format (which is sort of what's happening in that session var i think).

cmd /c powershell -file "c:\users\meiguess\desktop\eric.ps1" you me

eric.ps1

param ($one,$two)
$myout = "hi there $one, this is $two"
write-output $myout > "c:\users\meiguess\desktop\eric.txt"