0

I'm trying to pass the user input computer name to the psexec command. I've tried about everything. I know the command works because if I run the file by manually entering the computer name is successful. I need to get the strComputer variable into the \strComputer psexec command. Thanks in advance.

Set objShell = CreateObject("Wscript.shell")

Dim strComputer

strComputer=InputBox("Run app on remote computer",,"Type name here & click OK")

objShell.run("powershell psexec.exe -i -s \\strComputer \\domain.com\folder\app.exe domain.com")

MsgBox("Scan complete")
hollopost
  • 569
  • 9
  • 28
Kevin_A
  • 1
  • 1
  • 2
    Why on earth are you mixing Vbs *and* Powershell with Cli tools? – vonPryz Jan 21 '14 at 17:25
  • I guess because I'm not experienced with this. What would be the best solution to perform a psexec on a remote machine? I couldn't even get the psexec to run until I added the powershell. – Kevin_A Jan 21 '14 at 20:28

1 Answers1

0

Why not use a PowerShell script for this?

Contents of myscript.ps1
------------------------
$computerName = Read-Host "Enter name of remote computer"
psexec \\$computerName -i -s \\domain.com\folder\app.exe domain.com
"Scan complete"
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Thanks @Keith. I tried to run that, but I don't think GP will allow it. I just get some red text and the PS window disappears. For some reason it will run if I use the way I have it in the original posting. – Kevin_A Jan 22 '14 at 12:59
  • @Kevin_A Is this a logon script? Also, when you run this using powershell.exe you may need to use the parameter `-ExeuctionPolicy Unrestricted`. – Keith Hill Jan 22 '14 at 16:52
  • No, not a logon script. I just want to run a LAN monitoring app we use on a remote machine manually. I can run it like I typed above by just entering the actual computer name instead of \\computerName. I don't understand. The Get-ExecutionPolicy returns Restricted, but I can't change it. I read the page at http://technet.microsoft.com/en-us/library/ee176949.aspx and tried to change the policy, but I am not allowed to alter the reg key. I don't understand how it can run with the powershell command within the objShell.run() method. It doesn't make sense. – Kevin_A Jan 22 '14 at 17:36
  • Just an error saying that the exectution of scripts is disabled on this system, yet I can run the powershell through the .vbs file... – Kevin_A Jan 22 '14 at 17:41
  • In the VBS file you aren't technically running a PowerShell script i.e. a .ps1 file. Even though execution policy is set to restricted, the user can still execute commands interactively in a PowerShell console. Your VBS script is more or less operating in that mode. When you run `Set-ExecutionPolicy RemoteSigned` make sure you're running that from an elevated/admin console. – Keith Hill Jan 22 '14 at 18:02
  • Thanks @Keith. I was able to set execution policy with run as admin. I'll just use the powershell script. Thanks. – Kevin_A Jan 22 '14 at 18:10