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
2 answers

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…
sk904861
  • 1,247
  • 1
  • 14
  • 31
2
votes
2 answers

Why does PowerShell not work if I use WinRS?

I have a file "test.ps1" and its content is as below: $getRSDBName = { Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $rsdb = Get-SPRSDatabase return $rsdb } $rsdb = invoke-command -scriptblock…
2
votes
2 answers

invoke-command doesn't work as expected

I'm trying to use invoke-command to find a specific process using this code Invoke-Command -ComputerName $selected_server.ServerName -ArgumentList $selected_server.ProcessId -ScriptBlock {Get-Process -Name "winlogon" | where{$_.Id -like $args[0]}…
Naigel
  • 9,086
  • 16
  • 65
  • 106
2
votes
2 answers

powershell remote

I am trying to run this from my local machine (Win7 & PS v2.0) cls $sess = Enter-PSSession -ComputerName blmcrmpoc Invoke-Command -Session $sess -Scriptblock { $path = "C:\inetpub\logs\LogFiles" $lastWrite = (Get-Date).AddDays(-90) $oldLogs =…
PickyTech
  • 135
  • 3
  • 9
2
votes
1 answer

Powershell passing variables to remote script

I have the following cmd file:- PowerShell.exe -noexit E:\wwwroot\domains\processes\AddDirectory.ps1 -Param testdomain.co.uk which goes through to:- $Session = New-PSSession -ComputerName 192.168.0.25 $script = { Param($Param1) set-executionpolicy…
Paul
  • 23
  • 1
  • 4
2
votes
1 answer

Powershell Invoke-Command Access Denied on remote symbolic link

On Machine A (Windows 8) I've created a symbolic link to a network share on Machine B (Windows 7) in order to compile some specific Windows 8 code. In order to do this I call Invoke-Command from Machine B but I get the following error: Access is…
John Bowker
  • 109
  • 1
  • 3
  • 11
2
votes
1 answer

Powershell invoke-command script return code

I'm working on a deployment script for a vendor application. It reads an xml that maps the deploy paths for the various environments, then iterates over the various servers and copies the correct files over and executes the rollout script. I would…
JDH
  • 2,618
  • 5
  • 38
  • 48
1
vote
5 answers

Powershell Remote Invoke-Command Start-Process App Immediately Closes After Launch

I am working on a script to remotely kill two processes, delete some folders, and launch a service as an application. Eventually this will be deployed to run against multiple servers, but I'm currently testing it against a single server. Everything…
1
vote
1 answer

How to execute script block on remote machine that uses local variable as an argument

I would like to run an application passing it arguments from a remote machine. I've got the following to work on the remote machine by running it locally: foreach ($a in $args){ &"c:\Program Files\ChristianSteven\CRD\crd.exe" "-s…
dads
  • 17
  • 1
  • 5
1
vote
1 answer

Using variable in Select-Object in Powershell

I have a table which is created using Time as the Column names. However if the first row does not have data in certain Hours(column) then the column does not show the column for the rest of the table. Thus, I'm trying to create a dynamic select…
1
vote
1 answer

Powershell - Invoke-Command : Parameter set cannot be resolved using the specified named parameters

[Could not find any relevant nor working answer, I checked the parameters, they are legit] I try to run an executable with its respective parameters, but with powershell here is the line: Invoke-Command -FilePath "$execPath\xxxxxxxxxxxxxx.exe"…
1
vote
1 answer

Run Powershell Script as Administrator remotely

Script_A.ps1 on Server A: Invoke-Command -ComputerName Server B -ScriptBlock{ Set-Location "C:\Path" .\Script_B.ps1 } The Script "Script_B.ps1": Set-Location "C:\Path" .\Script_C.ps1 -Verb RunAs -Force Script_C needs elevated permissions…
1
vote
1 answer

How to login with different user credential while creating GCE instance using powershell startup script

I am trying following--> Creating GCE instance via gcloud cmds As a metadata I am providing ps1 scripts which is creating User and adding to required domain Once user created I need to use that user credential and run few commands as…
1
vote
1 answer

Powershell GUI - Output to textbox from Invoke-Command function

I'm converting my current backup solution for our whole environment to Powershell GUI application. My script is working as intended but now I'm trying to display the output to my GUI textbox field. The output I'm trying to display is inside a…
1
vote
1 answer

Run Linux terminal commands in Android program

I am developing a small app that would synchronize a directory present in my android phone with that of my laptop. I rooted my phone and also installed rsync in that so as to synchronize the directories across my phone and laptop. I checked it…
nikhil
  • 9,023
  • 22
  • 55
  • 81