How to call a PowerShell file with parameters using VBScript





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Greetings everyone and Happy New Year.



I just learned about PowerShell two days ago and it shows. I am trying to make custom Balloon tips and didn't what to make separate ps1 scripts for every possible event. What I needed was a ps1 with parameters.



I found this bit of code at this site:
GitHub Invoke-BalloonTip



And I call successfully call it from the PS window with:



 . .Invoke-BalloonTip.ps1
Invoke-BalloonTip -Message 'Message' -Title 'Title' -MessageType Info


However, I need to call this from a VBScript. I have tried:



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command . c:PowerShellTestInvoke-BalloonTip.ps1" & Invoke-BalloonTip -Message 'Invoked' -Title 'Invoked' -MessageType Info)


And



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command ""& { . c:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message 'Message' -Title 'Title' MessageType Info }""")


And a few others with unsatisfactory results. These two examples are the only ones that show no errors in the PS window when it runs. With these two examples the PS window will show briefly and display no error messages but no Balloon Tip will display.



I am certain it is a syntax issue but I am out of ideas as to what it may be. Any ideas or suggestions are welcome and appreciated.










share|improve this question























  • Prepend the -command arguments with -noexit to have the window stay open so you can see any errors it might throw: "powershell -noexit -command ""..."

    – Mathias R. Jessen
    Jan 3 at 10:51











  • Thank for that, I will keep that in mind

    – John Clark
    Jan 3 at 11:18


















0















Greetings everyone and Happy New Year.



I just learned about PowerShell two days ago and it shows. I am trying to make custom Balloon tips and didn't what to make separate ps1 scripts for every possible event. What I needed was a ps1 with parameters.



I found this bit of code at this site:
GitHub Invoke-BalloonTip



And I call successfully call it from the PS window with:



 . .Invoke-BalloonTip.ps1
Invoke-BalloonTip -Message 'Message' -Title 'Title' -MessageType Info


However, I need to call this from a VBScript. I have tried:



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command . c:PowerShellTestInvoke-BalloonTip.ps1" & Invoke-BalloonTip -Message 'Invoked' -Title 'Invoked' -MessageType Info)


And



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command ""& { . c:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message 'Message' -Title 'Title' MessageType Info }""")


And a few others with unsatisfactory results. These two examples are the only ones that show no errors in the PS window when it runs. With these two examples the PS window will show briefly and display no error messages but no Balloon Tip will display.



I am certain it is a syntax issue but I am out of ideas as to what it may be. Any ideas or suggestions are welcome and appreciated.










share|improve this question























  • Prepend the -command arguments with -noexit to have the window stay open so you can see any errors it might throw: "powershell -noexit -command ""..."

    – Mathias R. Jessen
    Jan 3 at 10:51











  • Thank for that, I will keep that in mind

    – John Clark
    Jan 3 at 11:18














0












0








0








Greetings everyone and Happy New Year.



I just learned about PowerShell two days ago and it shows. I am trying to make custom Balloon tips and didn't what to make separate ps1 scripts for every possible event. What I needed was a ps1 with parameters.



I found this bit of code at this site:
GitHub Invoke-BalloonTip



And I call successfully call it from the PS window with:



 . .Invoke-BalloonTip.ps1
Invoke-BalloonTip -Message 'Message' -Title 'Title' -MessageType Info


However, I need to call this from a VBScript. I have tried:



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command . c:PowerShellTestInvoke-BalloonTip.ps1" & Invoke-BalloonTip -Message 'Invoked' -Title 'Invoked' -MessageType Info)


And



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command ""& { . c:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message 'Message' -Title 'Title' MessageType Info }""")


And a few others with unsatisfactory results. These two examples are the only ones that show no errors in the PS window when it runs. With these two examples the PS window will show briefly and display no error messages but no Balloon Tip will display.



I am certain it is a syntax issue but I am out of ideas as to what it may be. Any ideas or suggestions are welcome and appreciated.










share|improve this question














Greetings everyone and Happy New Year.



I just learned about PowerShell two days ago and it shows. I am trying to make custom Balloon tips and didn't what to make separate ps1 scripts for every possible event. What I needed was a ps1 with parameters.



I found this bit of code at this site:
GitHub Invoke-BalloonTip



And I call successfully call it from the PS window with:



 . .Invoke-BalloonTip.ps1
Invoke-BalloonTip -Message 'Message' -Title 'Title' -MessageType Info


However, I need to call this from a VBScript. I have tried:



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command . c:PowerShellTestInvoke-BalloonTip.ps1" & Invoke-BalloonTip -Message 'Invoked' -Title 'Invoked' -MessageType Info)


And



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -command ""& { . c:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message 'Message' -Title 'Title' MessageType Info }""")


And a few others with unsatisfactory results. These two examples are the only ones that show no errors in the PS window when it runs. With these two examples the PS window will show briefly and display no error messages but no Balloon Tip will display.



I am certain it is a syntax issue but I am out of ideas as to what it may be. Any ideas or suggestions are welcome and appreciated.







powershell vbscript system-tray






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 10:04









John ClarkJohn Clark

31




31













  • Prepend the -command arguments with -noexit to have the window stay open so you can see any errors it might throw: "powershell -noexit -command ""..."

    – Mathias R. Jessen
    Jan 3 at 10:51











  • Thank for that, I will keep that in mind

    – John Clark
    Jan 3 at 11:18



















  • Prepend the -command arguments with -noexit to have the window stay open so you can see any errors it might throw: "powershell -noexit -command ""..."

    – Mathias R. Jessen
    Jan 3 at 10:51











  • Thank for that, I will keep that in mind

    – John Clark
    Jan 3 at 11:18

















Prepend the -command arguments with -noexit to have the window stay open so you can see any errors it might throw: "powershell -noexit -command ""..."

– Mathias R. Jessen
Jan 3 at 10:51





Prepend the -command arguments with -noexit to have the window stay open so you can see any errors it might throw: "powershell -noexit -command ""..."

– Mathias R. Jessen
Jan 3 at 10:51













Thank for that, I will keep that in mind

– John Clark
Jan 3 at 11:18





Thank for that, I will keep that in mind

– John Clark
Jan 3 at 11:18












2 Answers
2






active

oldest

votes


















1














I think the issue is with the original Invoke-BalloonTip.ps1 as it tries to use the System.Windows.Forms.ToolTipIcon type before it is available (via loading System.Windows.Forms). Adding it earlier in your command should fix things (though it does seem a bit hacky):



Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""Message"" -Title ""Title"" -MessageType Info}""")


Invoke-BalloonTip.ps1 works straight away in the PowerShell ISE as the correct assembly is already loaded by default, but not so in powershell.exe or VSCode.






share|improve this answer
























  • You sir (ma'am?) are a genius! It worked perfectly and I really appreciate the explanation. Now on to the next issue!

    – John Clark
    Jan 3 at 11:19



















0














For the sake of anyone else who comes here with a similar problem, this will not work if there are spaces in your Message or Title. To fix it, I surrounded the strings with single quotes:



objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""'Message with Space'"" -Title ""'Title With Space:'"" -MessageType info}""")





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020042%2fhow-to-call-a-powershell-file-with-parameters-using-vbscript%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I think the issue is with the original Invoke-BalloonTip.ps1 as it tries to use the System.Windows.Forms.ToolTipIcon type before it is available (via loading System.Windows.Forms). Adding it earlier in your command should fix things (though it does seem a bit hacky):



    Set objShell = CreateObject("Wscript.shell")
    objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""Message"" -Title ""Title"" -MessageType Info}""")


    Invoke-BalloonTip.ps1 works straight away in the PowerShell ISE as the correct assembly is already loaded by default, but not so in powershell.exe or VSCode.






    share|improve this answer
























    • You sir (ma'am?) are a genius! It worked perfectly and I really appreciate the explanation. Now on to the next issue!

      – John Clark
      Jan 3 at 11:19
















    1














    I think the issue is with the original Invoke-BalloonTip.ps1 as it tries to use the System.Windows.Forms.ToolTipIcon type before it is available (via loading System.Windows.Forms). Adding it earlier in your command should fix things (though it does seem a bit hacky):



    Set objShell = CreateObject("Wscript.shell")
    objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""Message"" -Title ""Title"" -MessageType Info}""")


    Invoke-BalloonTip.ps1 works straight away in the PowerShell ISE as the correct assembly is already loaded by default, but not so in powershell.exe or VSCode.






    share|improve this answer
























    • You sir (ma'am?) are a genius! It worked perfectly and I really appreciate the explanation. Now on to the next issue!

      – John Clark
      Jan 3 at 11:19














    1












    1








    1







    I think the issue is with the original Invoke-BalloonTip.ps1 as it tries to use the System.Windows.Forms.ToolTipIcon type before it is available (via loading System.Windows.Forms). Adding it earlier in your command should fix things (though it does seem a bit hacky):



    Set objShell = CreateObject("Wscript.shell")
    objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""Message"" -Title ""Title"" -MessageType Info}""")


    Invoke-BalloonTip.ps1 works straight away in the PowerShell ISE as the correct assembly is already loaded by default, but not so in powershell.exe or VSCode.






    share|improve this answer













    I think the issue is with the original Invoke-BalloonTip.ps1 as it tries to use the System.Windows.Forms.ToolTipIcon type before it is available (via loading System.Windows.Forms). Adding it earlier in your command should fix things (though it does seem a bit hacky):



    Set objShell = CreateObject("Wscript.shell")
    objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""Message"" -Title ""Title"" -MessageType Info}""")


    Invoke-BalloonTip.ps1 works straight away in the PowerShell ISE as the correct assembly is already loaded by default, but not so in powershell.exe or VSCode.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 3 at 10:51









    boxdogboxdog

    3,4182515




    3,4182515













    • You sir (ma'am?) are a genius! It worked perfectly and I really appreciate the explanation. Now on to the next issue!

      – John Clark
      Jan 3 at 11:19



















    • You sir (ma'am?) are a genius! It worked perfectly and I really appreciate the explanation. Now on to the next issue!

      – John Clark
      Jan 3 at 11:19

















    You sir (ma'am?) are a genius! It worked perfectly and I really appreciate the explanation. Now on to the next issue!

    – John Clark
    Jan 3 at 11:19





    You sir (ma'am?) are a genius! It worked perfectly and I really appreciate the explanation. Now on to the next issue!

    – John Clark
    Jan 3 at 11:19













    0














    For the sake of anyone else who comes here with a similar problem, this will not work if there are spaces in your Message or Title. To fix it, I surrounded the strings with single quotes:



    objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""'Message with Space'"" -Title ""'Title With Space:'"" -MessageType info}""")





    share|improve this answer




























      0














      For the sake of anyone else who comes here with a similar problem, this will not work if there are spaces in your Message or Title. To fix it, I surrounded the strings with single quotes:



      objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""'Message with Space'"" -Title ""'Title With Space:'"" -MessageType info}""")





      share|improve this answer


























        0












        0








        0







        For the sake of anyone else who comes here with a similar problem, this will not work if there are spaces in your Message or Title. To fix it, I surrounded the strings with single quotes:



        objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""'Message with Space'"" -Title ""'Title With Space:'"" -MessageType info}""")





        share|improve this answer













        For the sake of anyone else who comes here with a similar problem, this will not work if there are spaces in your Message or Title. To fix it, I surrounded the strings with single quotes:



        objShell.run("powershell.exe -command ""& {Add-Type -AssemblyName System.Windows.Forms;. C:PowerShellTestInvoke-BalloonTip.ps1; Invoke-BalloonTip -Message ""'Message with Space'"" -Title ""'Title With Space:'"" -MessageType info}""")






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 16:02









        John ClarkJohn Clark

        31




        31






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020042%2fhow-to-call-a-powershell-file-with-parameters-using-vbscript%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory