Questions tagged [invoke-command]

Invoke-Command is a powershell cmdlet that runs commands on local and remote computers.

Invoke-Command is a powershell cmdlet that runs commands on local and remote computers and returns all output from the commands, including errors. With a single Invoke-Command command, you can run commands on multiple computers.

To run a single command on a remote computer, use the ComputerName parameter. To run a series of related commands that share data, use the New-PSSession cmdlet to create a PSSession (a persistent connection) on the remote computer, and then use the Session parameter of Invoke-Command to run the command in the PSSession. To run a command in a disconnected session, use the InDisconnectedSession parameter. To run a command in a background job, use the AsJob parameter.

You can also use Invoke-Command on a local computer to evaluate or run a string in a script block as a command. Windows PowerShell converts the script block to a command and runs the command immediately in the current scope, instead of just echoing the string at the command line.

555 questions
2
votes
3 answers

PowerShell remote invocation mysteriously hangs

I have created a series of functions that basically collect all the IIS configurations about a site, when run on a server locally it executes without issue (albeit slowly) however when I run them remotely using an invoke-command in PowerShell 2 it…
Justin
  • 1,303
  • 15
  • 30
2
votes
1 answer

How can I run Protractor tests on a remote machine

I want to run my protractor tests on a virtual machine. I already tried running it with the following command: Invoke-Command -ComputerName 10.2.1.7 -Port 5985 -Credential $credential -ScriptBlock{ protractor…
andreaspfr
  • 2,298
  • 5
  • 42
  • 51
2
votes
2 answers

Remote Powershell script fails to install .exe

EDIT2: **After much testing and reading I've realised this is a powershell limitation "environmental snag." (read more here). I've resolved the issue by running the .exe as a task via schtasks.exe ** EDIT: After much testing the problem seems to…
Petar
  • 51
  • 1
  • 7
2
votes
1 answer

Close PS1 after passing argu to second ps1 file via invoke-expression

I have GUI that has many function on but one thing i need to build in to it is the staff id number of the member of staff using it so i can add other features. i am trying to do this by creating a login box.(there is no need for password) my first…
2
votes
1 answer

Running a Setup.exe from a network share, via Invoke-Command in Powershell

PSEXEC started to give me some trouble, and I decided to recode in PowerShell. This batch command used to work for me, before PSEXEC started messing things up: psexec -accepteula \\ -u -p cmd /c…
Simon Bruun
  • 87
  • 1
  • 2
  • 11
2
votes
1 answer

How do you modify arguments sent to built in command in powershell v2?

In powershell v3 you can use $executionContext.SessionState.InvokeCommand.PostCommandLookupAction and CommandScriptBlock to modify the arguments. How can you accomplish the same thing in v2? Powershell 3…
sclarson
  • 4,362
  • 3
  • 32
  • 44
2
votes
2 answers

How to pass string variable to invoke-expression?

I am running the below powershell command: $cmd = "xxx.exe" Invoke-Command -ComputerName localhost {Invoke-Expression $cmd} However I get the error: Cannot bind argument to parameter 'Command' because it is null. + CategoryInfo :…
Sheen
  • 3,333
  • 5
  • 26
  • 46
2
votes
1 answer

Scriptblock works as Invoke-Command, but not as Start-Job

I have written a ScriptBlock that POSTs file uploads to a custom http server and saves the response to disk. It is intended to be used for testing said server and in addition to checking the correct response I'd like to run it in parallel to load…
Marian Aldenhövel
  • 677
  • 1
  • 6
  • 24
2
votes
0 answers

Returning Remote PowerShell Objects

I'm fairly inexperienced in PoSh, however I think I can hold my own on the noob circuit. I'm trying to work on a mechanism to retrieve direct attached storage (DAS) from a list of servers in a SQL table via PowerShell. The commands to grab the DAS…
pgapepper
  • 21
  • 2
2
votes
2 answers

Invoke-command and msiexec

I'm trying to remove an application on a remote machine using the Invoke-Command cmdlet but it's not working. Here is my script: Invoke-Command -ComputerName "Computername" -Verbose -ScriptBlock { msiexec.exe /x…
JoeRod
  • 899
  • 8
  • 20
  • 30
2
votes
1 answer

Calling a function within a function with invoke-command Powershell

I am hoping to call a function within a function in invoke-command. It looks like I am not doing this properly. I get "get-group_users" is not recognized error. Everything is in one ps1 script. Truncated Script: function get-session { $session =…
snoop
  • 379
  • 3
  • 8
  • 21
2
votes
1 answer

Run powershell script from within a powershell script

I have a perl script perl1.pl. Within the perl script I call a powershell script script1.ps1. In script.ps1 I call other script like script2.ps1 with local variables as parameters. I have prepared a powershell script script3.ps1. I want to run…
JustSam
  • 41
  • 1
  • 2
  • 3
2
votes
2 answers

Using invoke-command from C# throwing exception

I have tried the following case from powershell terminal : invoke-command -connectionuri "http://FullMachineName/wsman" -configuration "http ://schemas.microsoft.com/powershell/Microsoft.PowerShell" -credential "MachineName\Administrator" -filepath…
cmm user
  • 2,426
  • 7
  • 34
  • 48
2
votes
3 answers

PowerShell sometimes fail to execute .exe

I am trying to script something to sync up IIS servers using MSdeploy. I tried all the possible ways to run the .exe but sometimes I get this error: The term 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' is not recognized as the name…
laitha0
  • 4,148
  • 11
  • 33
  • 49
2
votes
1 answer

PowerShell Invoke-Command remotely using a share

I am trying to install software (.exe) with PowerShell remotely on another computer. I have now: Invoke-Command -Authentication Credssp -Credential $cred -ComputerName "TargetComputer01" -ScriptBlock {Start-Process -FilePath $args[0] -ArgumentList…
JustRonald
  • 103
  • 3
  • 10