Link to home
Start Free TrialLog in
Avatar of Rick Rudolph
Rick RudolphFlag for United States of America

asked on

Run VBScript on a remote computer with parameters

I have a vbscript that runs correctly on an Exchange Server The goal is to create a mailbox from the command line.

This is the script:

Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell.exe -noexit c:\temp\RJRcreatemailbox.ps1 RickRudolph")

This script runs a powershell script which creates a mailbox for RickRudolph, email address of

Now what I want to do is to be able to run this script remotely from MSAccess VBA and pass the 2 parameters to the Exchange Server

Any ideas on the best way to do this?

Thank you,

Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

why run vbs to run PowerShell?

you can try connecting with WMI to the remote machine
   Set objProcess = objWMIService.Get("Win32_Process")

Dim strProcess
    strProcess = "c:\windows\system32\Windowspowershell\v1.0\powershell.exe -noexit c:\temp\RJRcreatemailbox.ps1 RickRudolph")

Dim lngReturn, intPID
    lngReturn = objProcess.Create(strProcess, null, null, intPID)

    If lngReturn = 0 Then
        Wscript.Echo strProcess + " started. PID: " & intPID
        Wscript.Echo "Error: " & lngReturn
    End If

Open in new window

Why the -noexit parameter?
Avatar of Rick Rudolph


I was unsure of how to run the PowerShell script from VBA

Thank you for the idea. I have never used WMI, I don't see any reference to the server name, should that be placed in front of the c:\temp with UNC naming?

The noexit should go

Can you clarify how the server name is referenced?

Thank you,
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

thanks very much, a big help.