We're launching a PowerShell script with the help of vbs to avoid the pop-up it generates. This works flawlessly as you can see below:
PS_Launcher.vbs:
'run window totally hidden
Dim oSHELL
Set oSHELL = CreateObject("WScript.Shell")
oSHELL.CurrentDirectory = "C:\users\bob\AppData\Local\Temp"
oSHELL.Run "powershell.exe -ExecutionPolicy Bypass -NoLogo -File .\PS_Script.ps1", 0
Set oSHELL = Nothing
The only problem is when we run this from within a scheduled task or from the command prompt (CMD), it doesn't wait for the PowerShell script to finish and immediately returns the prompt.
Is there a way to have it wait for the PowerShell script to finish before continuing?
We've tried the following as described in bWaitForReturn, but no luck:
oSHELL.Run "powershell.exe -ExecutionPolicy Bypass -NoLogo -File .\PS_Script.ps1", 0, True
PS_Script.ps1:
Start-Sleep -Seconds 15
Get-WmiObject -Class Win32_MappedLogicalDisk |
Select-Object Name, ProviderName |
Export-Csv .\PS_Data.txt -NoTypeInformation
Start-Sleep -Seconds 15