Running legacy VBScripts from PowerShell

Page content

VBScript can feel like a thing of the past, but truth is a lot of companies have invested heavily in VBScript during many years. It all can’t be simply translated to PowerShell over a night. To get started with translating VBScripts to PowerShell, one way could be to break up the VBScripts into usable parts. This way we can start translating the Control Scripts to PowerShell and keep the using the VBScripts as is. Then we can replace the VBScripts part by part.

The first step is to create a reliable and reusable to invoke VBScripts from PowerShell. For this task I wrote Invoke-VBScript.

Invoke-VBScript can be run in three different ways:

  • With regular parameters
  • Accepting script path from pipeline (ByValue)
  • Accepting script path and argument from pipeline (ByPropertyName)

Regular parameters

Invoke-VBScript -Path .vbscript.vbs -Argument 'Arg 1', 'Arg 2' -Wait

Value from pipeline (ByValue)

.vbscript.vbs | Invoke-VBScript -Argument 'Arg 1', 'Arg 2' -Wait

Value from pipeline (ByPropertyName)

$Input = [pscustomobject]@{Path = '.vbscript.vbs';Argument='Arg 1', 'Arg 2'}<br /> $Input | Invoke-VBScript -Wait

All three examples will give the same output. As long as the Wait parameter is specified, the function will wait for the script to complete and return one single string containing the output from the VBScript. If the Wait parameter is left out, the script will instead return a job reference to the job started.

The script is available for download from Technet Gallery.