none
Callin Parameters from a .VBS to Powershell RRS feed

  • Question

  • I'm using the following code to call a .ps1 file from a .vbs script. I need to pass a total of 5 parameters from the .vbs to the .ps1. For some reason I am only able to pass 3. I'm very weak in .vbs so please let me know if there is anything wrong with what I am doing: The script runs without errors but only passes the first 3 parms:

    I am calling the script like this:

    Call-AuthAlert.vbs one two three four five

    Dim objShell
    Set objShell = WScript.CreateObject ("WScript.shell")

    objShell.run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File c:\Scripts\AuthAlertsScript\AuthAlerts.ps1 " & chr(34) & WScript.Arguments.Item(0) & chr(34) & " " & chr(34) & WScript.Arguments.Item(1) & chr(34) & " " & chr(34) & WScript.Arguments.Item(2) & chr(34) & " " & chr(34) & WScript.Arguments.Item(3) & chr(34) & " " & chr(34) & WScript.Arguments.Item(4)

    Set objShell = Nothing


    • Edited by CMR NYC Thursday, January 22, 2015 7:08 PM
    Thursday, January 22, 2015 3:48 AM

Answers

  • Bill was very close:

    objShell.Run "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" _
      & " -File c:\Scripts\AuthAlertsScript\AuthAlerts.ps1" _
      & " """ & WScript.Arguments.Item(0) & """" _
      & " """ & WScript.Arguments.Item(1) & """" _
      & " """ & WScript.Arguments.Item(2) & """" _
      & " """ & WScript.Arguments.Item(3) & """" _
      & " """ & WScript.Arguments.Item(4) & """"

    One more & was needed.


    ¯\_(ツ)_/¯

    • Marked as answer by CMR NYC Wednesday, January 28, 2015 8:29 PM
    Thursday, January 22, 2015 7:01 PM

All replies

  • Why do you need to call a PowerShell script from VBScript?

    Why not just run the PowerShell command line directly?


    -- Bill Stewart [Bill_Stewart]

    Thursday, January 22, 2015 3:59 AM
    Moderator
  • I'm using SCOM to call the .vbs script and the version I am using is not able to call a .ps1 directly.
    Thursday, January 22, 2015 4:07 AM
  • Try it this way:


    objShell.Run "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" _
      & " -File c:\Scripts\AuthAlertsScript\AuthAlerts.ps1" _
      & " """ WScript.Arguments.Item(0) & """" _
      & " """ WScript.Arguments.Item(1) & """" _
      & " """ WScript.Arguments.Item(2) & """" _
      & " """ WScript.Arguments.Item(3) & """" _
      & " """ WScript.Arguments.Item(4) & """"
    


    -- Bill Stewart [Bill_Stewart]

    Thursday, January 22, 2015 1:44 PM
    Moderator
  • This still seems to have an issue see the screen shot below:
    Thursday, January 22, 2015 6:58 PM
  • Bill was very close:

    objShell.Run "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" _
      & " -File c:\Scripts\AuthAlertsScript\AuthAlerts.ps1" _
      & " """ & WScript.Arguments.Item(0) & """" _
      & " """ & WScript.Arguments.Item(1) & """" _
      & " """ & WScript.Arguments.Item(2) & """" _
      & " """ & WScript.Arguments.Item(3) & """" _
      & " """ & WScript.Arguments.Item(4) & """"

    One more & was needed.


    ¯\_(ツ)_/¯

    • Marked as answer by CMR NYC Wednesday, January 28, 2015 8:29 PM
    Thursday, January 22, 2015 7:01 PM
  • jrv is correct, I forgot the & on the left side of the WScript.Arguments.Item(n) elements:


    objShell.Run "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" _
      & " -File c:\Scripts\AuthAlertsScript\AuthAlerts.ps1" _
      & " """ & WScript.Arguments.Item(0) & """" _
      & " """ & WScript.Arguments.Item(1) & """" _
      & " """ & WScript.Arguments.Item(2) & """" _
      & " """ & WScript.Arguments.Item(3) & """" _
      & " """ & WScript.Arguments.Item(4) & """"
    

    Sorry for the confusion.


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by jrv Thursday, January 22, 2015 8:55 PM
    Thursday, January 22, 2015 7:29 PM
    Moderator