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

Invoke-Command Start-Process with named parameters

I'm totally new to PowerShell. All I'm trying to do is call an .exe on a remote computer using named parameters. $arguments = "-clientId TX7283 -batch Batch82Y7" invoke-command -computername FRB-TER1 { Start-Process -FilePath "C:\Program Files…
zorrinn
  • 45
  • 1
  • 6
2
votes
2 answers

Run .ps1 on remote machine

I need to execute powershell script on remote computer with admin privilegies. I have 2 scripts: client and server. When i start client.ps1 i invoke command on server machine but get access error. I get no error if I use simple code in server.ps1…
Damir
  • 99
  • 4
  • 11
2
votes
0 answers

How to invoke unit test a Print Event handler in c#

I have below method which will get invoked when I call Print() method. I need to unit test the same. Is there any suggestions on how to do this? internal PrintRemovalController(IApplicationContextHelper applicationContextHelper) { …
2
votes
1 answer

Encapsulate the output of invoke command in a variable - PowerShell

I have a script that installs Remote Desktop Services on remote machines (from the DC). I'm now at the phase where I check if RDS installed on the connection broker (server) and connection host (server). I want to use invoke-command since a remote…
Kahn Kah
  • 1,389
  • 7
  • 24
  • 49
2
votes
1 answer

Issues with powershell invoke-command, Unexpected token '-ArgumentList' in expression or statement

I am quite new to powershell. I am trying to remote to PCs in a csv file and extract the status of a registry key. However I get the error "Unexpected token '-ArgumentList' in expression or statement." when I try to execute. And I am not pretty sure…
Gideon Rufus
  • 29
  • 1
  • 3
2
votes
3 answers

Invoke-Command failed: WinRM cannot complete the operation

Using 2 machines, a local and a remote (with an address marked as remoteAddress), I'm trying to run this on the local machine: Invoke-Command -ComputerName remoteAddress -ScriptBlock { dir c:\ } but I get this error: [remoteAddress] Connecting to…
rotemp
  • 63
  • 1
  • 1
  • 8
2
votes
1 answer

Running Powershell script remotely through Java

I am able to run the below powershell command through Powershell itself, invoke-command -ComputerName "compName" -filepath "c:\script.ps1" -credential "admin" but when I try running that through Java, I get an error. Sounds like "Invoke-command" is…
Sara
  • 2,417
  • 7
  • 35
  • 52
2
votes
0 answers

Copy-Item not working with Remote PowerShell to copy files from network share to local drive on remote server

Set-ExecutionPolicy -ExecutionPolicy Bypass $webServers = "remoteservername1" $deploymentCredentials = Get-Credential Invoke-Command -ComputerName $webServers -Credential $deploymentCredentials -ScriptBlock { $appVersionDirectory =…
2
votes
1 answer

Script to get CPU Usage

I am using this script to get CPU usage from multiple server $Output = 'C:\temp\Result.txt' $ServerList = Get-Content 'C:\temp\Serverlist.txt' $CPUPercent = @{ Label = 'CPUUsed' Expression = { $SecsUsed = (New-Timespan -Start…
V T
  • 47
  • 10
2
votes
1 answer

Processing data returned from Invoke-Command as it's received?

I have a PowerShell script that I want to run on 5,000+ endpoints. The script enumerates a bunch of information about each host which I then want to be able to ingest into another program for analysis. The problem I'm having is that Invoke-Command…
tifkin
  • 526
  • 6
  • 14
2
votes
1 answer

Invoke-Command behavior clarification

I'm running into some trouble with the Invoke-Command cmdlet. I am logged into my local machine with my domain identity, which has admin rights on $server. If I manually enter my credentials, then use Invoke-Command, I get the error: Cannot open…
2
votes
1 answer

Comparing files based on version number and some criterias and Formatting the output

I am comparing dll files based on size, last write time and version number using Compare-object in Powershell. These files are stored on remote servers. I am getting the result. The only problem is how to get the value of the version number from the…
2
votes
0 answers

Powershell RestMethod upload inFile + Body

I am trying to create a script to send a file with a body but somehow is just ends up giving me error code (400) bad request or (412) so far this is what i have done $fileBin = [System.IO.File]::ReadAllBytes("$PSScriptRoot\$filePath") $data =…
Delita
  • 21
  • 2
2
votes
1 answer

Local or remote execution of powershell script with generic parameters

In a development team, I would like to have the same test scripts to be executed locally by a developper or remotely by our test platform. Here is what I would like to use as premises for each script # Test local/remote execution by reading C:\…
FoxAlfaBravo
  • 106
  • 1
  • 12
2
votes
1 answer

How to escape an Invoke-Webrequest in Powershell

I have a network device with a status page accessible by a Java applet. Using Fiddler I was able to find an http feed of the status, but the page has a constant refresh. (Firefox displays the page but keeps refreshing, Chrome sees it as an…
Tom Wiebe
  • 23
  • 1
  • 6