Executing invoke-item remotely in PowerShell - powershell

I am trying to execute this code willing to execute the program server.exe in the remote machine NODO-R01.Command completes, but nothing happens:
Invoke-Command -ComputerName NODO-R01 {Invoke-item C:\server.exe}
If I use any other *-Item cmdlet it works; like deleting, renaming, etc.

Related

Remote Powershell script causes Selenium to timeout

When I use Invoke-Command from a Powershell script to run an .exe that uses Selenium Chromedriver, the execution of my .exe hangs until I get a timeout exception.
I have tried running the .exe with a local Powershell command, and it works just fine every time. It is only when I use Invoke-Command that the .exe stops working. Is there any way to actually run powershell scripts remotely, without Invoke-Command because Invoke-Command doesn't seem to be doing what I want it to.
I've also tried to -Wait the process of the .exe but it still hangs.

Run script from Host onto PsSession Computer

I am trying to run the following code to run a script from my host computer onto a Vm that I have PSRemoted into (I am successfully remoted into the PSSession). Where am I going wrong?
Invoke-Command -FilePath C:\Script.ps1 -ComputerName PSRemoteComputer
You do not need to use both a PSSession and the Invoke-Command -ComputerName command as you have above. At that point, you'd be invoking C:\Script.ps1 on your VM and from your VM (which I assume doesn't exist, since C:\Script.ps1 exists on your machine).
If you exit your PSSession and run the command as you have typed it above, it should run correctly assuming PSRemoting is correctly enabled, and permissions for the script to run are set.
Keep in mind, objects are handled differently through PSRemoting, so if you are expecting a certain output you may be getting the deserialized version.

Invoke-Item executes file locally

I have a command
Invoke-Item \\remote_IP\share\setup.exe
That executes setup.exe on my local computer even though I specified "remote_IP" in the UNC path.
What is missing?
Your question isn't clear, but it looks like you are trying to remotely execute an application. You don't want Invoke-Item for that, you want Invoke-Command which has the -ComputerName switch (along with other things to facilitate remote execution like accepting credentials).
Invoke-Command -ComputerName RemoteIP -ScriptBlock {& 'C:\Path\To\Setup.exe'}
Or however you want to execute the file.
UNC paths have the following form \\remote_name\share_name\path. In your case the share_name is missing.
See https://en.wikipedia.org/wiki/Path_%28computing%29#Uniform_Naming_Convention
Also UNC paths only allow you to access file remotely, not execute them on the remote computer. For excecuting a program remotely you need a special service or tool support: https://serverfault.com/questions/221064/running-remotely-an-app-from-a-shared-folder-with-psexec
From PowerScript, however, you could also use the invoke-command command (see http://technet.microsoft.com/en-us/library/hh849719.aspx)

Start a program or filepath remotely

With XP machines and eventually win7 machines. I am trying to find a way to start a program remotely from the commandline or even powershell if possible. Right now we can kill tasks using the "taskkill" command, but there doesn't seem to be an easy way to start them without extra programs. I want to be able to do it without deploying anything. I tried that Psexec but that didnt work.
Invoke-Command -ComputerName server01 -ScriptBlock { yourprogram.exe }
Check out technet:
The Invoke-Command cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors. With a single Invoke-Command command, you can run commands on multiple computers.
http://technet.microsoft.com/en-us/library/hh849719.aspx

Powershell's Invoke-Command not working when called from Windows Task Scheduler

I have a Powershell script, which is working just fine, when called from command line, but only partially fine when executed by the Windows Task Scheduler. The script looks as follows:
# Do things, which are always working.
$session = new-pssession -computername SRV
Invoke-Command -session $session -scriptblock { D:\script.bat }
# Do things, which are always working.
The task defined in the Task Scheduler is completed without errors. As you see, all parts before and after Invoke-Command are working, also when called by the Task Scheduler. Only the Invoke-Command itself is only working when called from the command line.
My only guess is, that the Powershell script is exiting prematurely, but I didn't find any way to confirm this or even solve the issue.
it is likely to be a permissions issue - as a test, run the task using the same credentials as when it is run at the command line...
I had the same issue with Invoke-Command when I called a script from Task Scheduler to run certain scriptblocks on multiple computers. I don't know why, but setting the "Start in" folder of the action to the folder of the script solved it.