Synchronously Call PowerShell script from VBScript
<p>I have a PowerShell script that I need to run from a VBScript and I need the VBScript to wait on the PowerShell to finish (but the two don't need to communicate at all). Here's code that will execute the powershell, but the VBScript doesn't wait:</p>



<pre class="lang-vb prettyprint-override"><code>Set objShell = (CreateObject("Wscript.shell"))

objShell.Run ("powershell -noexit -file e:\powershell\vb_to_powershell_test.ps1")

MsgBox("Powershell execution complete")
</code></pre>

<p>This script will pop up with "Powershell execution complete" instantly, while the PowerShell is still running.</p>

<p><a href="https://stackoverflow.com/questions/5968356/how-to-programmatically-wait-for-shell-command-to-finish-running">Apparently</a> there is a <code>True</code> flag I could add that forces VB to wait. Like so, maybe:</p>

<pre class="lang-vb prettyprint-override"><code>objShell.Run ("powershell -noexit -file e:\powershell\vb_to_powershell_test.ps1", True)
</code></pre>

<p>That isn't working for me, as the script always complains about "cannot use parenthesis when calling a sub", which is <a href="https://blogs.msdn.microsoft.com/ericlippert/2003/09/15/what-do-you-mean-cannot-use-parentheses/" rel="nofollow noreferrer">a whole thing</a>. </p>

<p>I suspect this is a VisualBasic vs. VB.NET issue, but I'm stuck with VisualBasic here.</p>

<p>What am I doing wrong?</p>