0

I have a VBScript file that I would like to run on a remote machine using invoke:

Invoke-Command -ScriptBlock { cscript.exe "C:\test.vbs" } -Computer Machine1

When I execute this command, nothing happens. Neither on the remote machine nor in the shell window on my local machine; the only lines that appear in my local shell window after executing are:

Microsoft (R) Windows Script Host Version 5.8

Copyright (C) Microsoft Corporation. All rights reserved.

But it stays like this and I am not able to do anything anymore with the shell. I also dont get any error msg. The VBScript itself is quite small and takes just a few seconds to run. Also I did try and run the VBScript on the remote host directly (in remote desktop) and it is working.

Any clue where I could get some details on why the remote call doesn't do anything?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
kalinkula
  • 3
  • 1
  • 5
  • I don't know a lot about using `Invoke-Command` which I assume is a PowerShell commandlet, but surely it's a permission issue? Have you enabled PowerShell Remoting? – user692942 Jul 06 '16 at 14:30
  • Yes i did: 'PS C:\Windows\system32> winrm quickconfig' 'WinRM service is already running on this machine.' 'WinRM is already set up for remote management on this computer.' – kalinkula Jul 06 '16 at 14:33
  • What about passing `-Credential` parameter with a valid user that can execute the script on the remote end? – user692942 Jul 06 '16 at 14:36
  • No changes - only that i am asked to provide my password after sending the command: `Invoke-Command -Computer Machine1 -Credential DOMAIN\USER -ScriptBlock { cscript.exe "C:\test.vbs" }` – kalinkula Jul 06 '16 at 14:44
  • i should add: i can provoke an error if i just add some invalid vb script into my test.vbs. That will throw an error msg right after execution. So, i assume that the remote machine is indeed trying to run this script - or am i wrong ? – kalinkula Jul 06 '16 at 14:46
  • Does the script have some output you expect to see? It likely is running if you don't get an error just nothing is coming back to the StdOut in the Command Line. What about if you pass `-Verbose`? – user692942 Jul 06 '16 at 14:48
  • i expect a file to be written to a directory, which is not happening...also i added a msgbox command, which also isn executed (i'd expect to see it when in remote desktop at the time of execution...) – kalinkula Jul 06 '16 at 14:50
  • 1
    Correct me if I'm wrong but your running the script remotely, doesn't that mean any popups etc will occur on the remote machine *(probably in the background processes, due to how PowerShell calls it)*. Do you have access to the remote machine to check? – user692942 Jul 06 '16 at 14:57
  • Yes i do....i expect the popup to appear on the remote machine, but i cant see it in my remote desktop session with this machine. however, i would at least expect the .txt file to be written...what is irritating me is the fact that the shell just doesnt seem to return after i execute and i have no clue if there is anything happening at all and if there is, what it is :( – kalinkula Jul 06 '16 at 15:00
  • 1
    Like I said it's likely a background process *(GUI is hidden)*. Are there any clues in Event Viewer on the remote machine? – user692942 Jul 06 '16 at 15:05
  • Well i do see an event when i execute the command, but it doesnt tell me very much – kalinkula Jul 06 '16 at 15:22
  • Maybe this will help - [Invoke-Command in a background job](http://stackoverflow.com/q/17696149/692942) – user692942 Jul 06 '16 at 15:24
  • 1
    Remotely run programs are INVISIBLE. You aren't allowed to interfere with an interactive user. –  Jul 06 '16 at 21:52
  • Show your VBScript code. The PowerShell code is obviously working, since the `cscript` banner is returned. Also, as others have already pointed out, remote execution does not interact with user desktops, so you need to make sure your script can run non-interactively (no popups, prompts, etc.) – Ansgar Wiechers Jul 09 '16 at 15:06

0 Answers0