Steps:
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.
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 eg 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.