0

Steps:

1. I have created a file known as: "test.vbs" under temp folder in machine B and in that script i have msgbox "hi"

2. From machine A - my goal is execute to test.vbs in machine B

3. In machine A. i did the following steps but i didnt get remote script executed. Can anyone please help me.

ps c:/> $s=new -pssession -computername machineB ps c:/> Invoke-Command -Session $s-ScriptBlock{$filecount=(Get-ChildItem c:\temp\test.vbs -Recurse)} ps c:/> Invoke-Command -Session $s-ScriptBlock{$filecount}

i received directory c:\temp and a file name as test.vbs

Now i want to execute test.vbs

ps c:/> Invoke-Command -ComputerName MachineB{& "C:\Temp\test.vbs"}

After executing the above command i dont see the test.vbs not executing remotely. my expectation is to get hi messagebox.

I am not understanding if it got executed or not.

can anyone please help me to execute remote script locally using power shell.

thanks inadvance.

1
  • Put the script in a shared folder which you can access from your local machine. Then just execute it, e.g. like this: \\remotemachine\sharedfolder\script.ps1 Commented Apr 22, 2018 at 14:12

1 Answer 1

0

If my understanding to your question is correct, you want to execute test.vbs against machine B from machine A, I don't think it's possible in PowerShell.

I faced the same issue some time ago. Neither Enter-PsSession nor Invoke-Command can do it for you probably just because they are not designed for this purpose. They are working totally fine if you run any PowerShell cmdlets remotely e.g. Get-Item you can easily get items on machine B. But once if you try to do something beyond the PowerShell remote session, like run a vbs script which will start a new CScript.exe process, it just won't work. It's due to some reason in underlying implementation of this PowerShell remoting.

If you do need to do that, I got two workarounds

  1. PsExec can be the best solution. It was designed to do this kind of work originally and it can easily accomplish what you want with a bunch of advanced features.
  2. Create a scheduled task on machine B by using New-ScheduledTask and let it trigger itself on machine B locally.
  3. If you have SCCM installed, it also provides this kind of functionality, check out this blog.
Sign up to request clarification or add additional context in comments.

1 Comment

Your understanding on my problem is correct. for #1. I agree that PSEXEC will be helpful and i have worked on that earlier but current company doesnot support in downloading PSExec., so thats y i m looking for powershell option. #2. Not a right choice for my situation because MachineB is a VM image and it expires for every 7 days. #3.i have gone through the link you have sgared for SCCM, basically it showed to install software silently remotely but my requirement is different wherein i need to execute remote scripts locally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.