Most old VBS scripts can be easily translated to PowerShell. The key command in VBS is “CreateObject” which lets you access system libraries. PowerShell translates...
Most old VBS scripts can be easily translated to PowerShell. The key command in VBS is “CreateObject” which lets you access system libraries. PowerShell translates “CreateObject” to “New-Object -ComObject”, yet the object model and member names stay the same:
This VBS script talks to you when you save it to a text file with “.vbs” extension:
There are only a few built-in VBS members such as MsgBox or InputBox. To translate these, all you need is importing the “Microsoft.VisualBasic.Interaction” type. This would be the PowerShell code to invoke MsgBox or InputBox:
Add-Type-AssemblyNameMicrosoft.VisualBasic$result= [Microsoft.VisualBasic.Interaction]::MsgBox("Do you want to restart?",3,"Question")
$result$result= [Microsoft.VisualBasic.Interaction]::InputBox("Your name?",$env:username,"Enter Name")
Visual Basic Members
Here is the complete list of supported Visual Basic members: