Avatar of Rick Rudolph
Rick Rudolph
Flag 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 rjr@somedomain.com")


This script runs a powershell script which creates a mailbox for RickRudolph, email address of rjr@somedomain.com

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,

Rick
PowershellExchangeVBA

Avatar of undefined
Last Comment
Rick Rudolph

8/22/2022 - Mon
David Johnson, CD

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 rjr@somedomain.com")


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

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

Open in new window


Why the -noexit parameter?
Rick Rudolph

ASKER
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,
ASKER CERTIFIED SOLUTION
David Johnson, CD

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rick Rudolph

ASKER
David,

thanks very much, a big help.


Rick
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy