none
VBscript passing multiple parameters to powershell RRS feed

  • Question

  • Hello,

    I am trying to run my ps1 script with parameters from VBscript.

    Variable sFirstname and sSurname has been already defined.

    I am able to call this script with one parameter and it works.

    sCmd = "Powershell.exe -File C:\HTA\test.ps1 -Firstname " & Chr(34) & sFirstname & Chr(34)
    Set xShell = CreateObject("Wscript.Shell")
    rReturn = xShell.Run(sCmd, 0, true)


    However my script, test.ps1 has two parameters -Firstname and -Surname.

    How do I call both of them using above mentioned variables?

    Something like:

    Powershell.exe -File C:\mypath\test.ps1 -Firstname  sFirstname  -Surname sSurname 
    Thank you!!

    Tuesday, December 23, 2014 3:53 PM

Answers

  • Just add -Surname and its argument onto the end of your sCmd string:


    sCmd = "powershell.exe -file C:\HTA\test.ps1 -firstname """ & sFirstname & """ -Surname """ & sSurname & """"

    This raises another question, though: Why run powershell.exe from VBScript? Why not just run the PowerShell script directly?


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Tuesday, December 23, 2014 4:00 PM
    • Marked as answer by Chrobak_77 Tuesday, December 23, 2014 6:34 PM
    Tuesday, December 23, 2014 3:56 PM
    Moderator

All replies

  • Just add -Surname and its argument onto the end of your sCmd string:


    sCmd = "powershell.exe -file C:\HTA\test.ps1 -firstname """ & sFirstname & """ -Surname """ & sSurname & """"

    This raises another question, though: Why run powershell.exe from VBScript? Why not just run the PowerShell script directly?


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Tuesday, December 23, 2014 4:00 PM
    • Marked as answer by Chrobak_77 Tuesday, December 23, 2014 6:34 PM
    Tuesday, December 23, 2014 3:56 PM
    Moderator
  • Hello Mark,

    First of all thank you very much for your answer I will test it in few minutes.

    And to your question,  this ps1 script has to be run from HTA application.
    And I suppose there is no way to run PS script directly from HTA...I know I could create simple GUI in PS using .net but in this case it is not an option as it has to be HTA.

    I am open to any suggestions though :).


    • Edited by Chrobak_77 Tuesday, December 23, 2014 4:24 PM
    Tuesday, December 23, 2014 4:22 PM