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
0
votes
0 answers

Register-ObjectEvent across computers

I'm trying to kick off an event subscription script in a remote box, which has the logic to subscribe to FileSystemWatcher 'file created' event locally. The script works fine locally. But when I execute it remotely from another machine (using…
0
votes
1 answer

PowerShell Invoke-Command asks for type

I need to add an application pool remotely and I was trying to use the following: $script = { Import-Module WebAdministration; New-Item IIS:\AppPools\$IRTPoolName; } Invoke-Command -ComputerName $targetName -ScriptBlock $script -credential…
0
votes
1 answer

Local variables in remote script

I've created a script to cycle through a spreadsheet with two columns. The problem I'm running into is that the local variables are not working when I run invoke-command. I've added the -ArgumentList parameter but I'm still getting an error about…
JoeRod
  • 899
  • 8
  • 20
  • 30
0
votes
1 answer

How to pass array arguments and something else?

$cmd = { param([System.Array]$filestocopy = $(throw "need files"), [bool]$copyxml) if($copy) #do stuff } $files = @("one","two","three") invoke-command -session $s -scriptblock $cmd -argumentlist (,$files)…
stewart99
  • 14,024
  • 7
  • 27
  • 42
0
votes
2 answers

pssession function not working

I have a particular use case that requires a lot of my powershell scripts to change the user context they run under. I have code that works reliably, but am trying to put it in to a function instead of repeating it in each script. Individually, the…
0
votes
1 answer

The result of same script is displayed in two formats while calling using powershell.invoke and pipeline.invoke

I am calling following script to display the local user accounts in a machine : $adsi = [ADSI]'WinNT://localhost'; $adsi.Children | where {$_.SchemaClassName -eq 'user'} |Select-Object @{n='UserName';e={$_.Name}}; When the above script is executed…
cmm user
  • 2,426
  • 7
  • 34
  • 48
0
votes
1 answer

Not able to execute the Power shell script from C# with Invoke-Command on a remote machine

I am not able to execute the Powershell file script from C# with Invoke-Command on a remote machine but at the same time I am able to execute the same script file using Invoke-Command on a remote machine through the PowerShell Command window with…
0
votes
0 answers

Use Powershellscript to start remote Powershellscrhipt with Parameters

I have a Powershell Script (PS1), which gets Events from a Remote Computer. When there is a special Event, it (PS1) should start a Powershell Script (PS2) which is on the remote Computer. The 2nd Script gets 2 Parameter from the first and the first…
0
votes
1 answer

Nested Invoke-Command results in PSSessionStateBroken, PSRemotingTransportException

I have three boxes: A, B, C. I'm trying to invoke a command on C from A without prompting for credentials. I can invoke command successfully a) on B from A b) on C from B but cannot invoke c) on C from A with nested Invoke-Command I think I can…
arturm
  • 1
  • 1
  • 1
0
votes
0 answers

How to run programs and scripts NOT in the background on a remote machine?

I have been trying to remotely execute some scripts and run some programs on a remote virtual machine on a server. The command I have been using is Invoke-command After going through all the troubles to make it work properly with the right…
FrozenLand
  • 259
  • 1
  • 4
  • 14
0
votes
1 answer

Cannot convert result form Invoke-Command to csv type

I have a problem with converting results from Invoke-Command into csv type. Code below : $remoteResultEventLog += Invoke-Command -ScriptBlock { Param ( [string]$EventLogName, [string]$EventLogEntryType, [DateTime]$EventLogAfter,…
Zabaa
  • 327
  • 1
  • 4
  • 16
0
votes
2 answers

Pass a powershell variable into a SQL value during out-datatable (invoke-sqlcmd2)

I want to insert a PowerShell variable value with a Select as I build a datatable from a SQL query. Borrowed function invoke-sqlcmd2 from TechNet gallery and dot-sourced it in. $NewSequenceID = invoke-sqlcmd2 -ServerInstance "MyServer" -Database…
apyo
  • 1
  • 1
  • 1
  • 2
0
votes
1 answer

Problems with running remote daemon (and not only) processes via PowerShell

From my script I want to run some command in remote Windows box. So I googled a little and seems the most popular and somehow standard way to do that is to use PowerShell's Invoke-Command cmdlet which seems to use the same protocol as winrm and…
0
votes
1 answer

Powershell remote install .exe file errors and not finding setup.iss file

Hi I am trying to figure out how to install .exe files to 5 server machine but I am having trouble trying to install silently on my own machine. I have this command Invoke-Command -ScriptBlock {Start-Process -FilePath…
0
votes
1 answer

Powershell error/exception handling

I am having some problems with handling errors/exceptions regarding the invoke-command. I am trying to catch errors when the target computer does not exist, however the message i am shown and the way the script in the catch block acts makes me think…
user1752736
  • 105
  • 1
  • 3
  • 10
1 2 3
36
37