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

Powershell improperly reading data in a CSV

I currently am writing a Powershell script that remotely removes users from a local admin group on a list of servers. The CSV headers are Computer and Name. For each entry of user (name), matches the server…
1
vote
0 answers

How to have a script wait for PowerShell on a remote server without using Restart-Computer

Afternoon guys, I'm working on a script that creates an initial Domain Controller. I've been running into an error and I feel like it's related to the creation of the Forest and the server restarting. The error in question is powershell remoting…
1
vote
1 answer

Using a remote Powershell Session to change a service username/password

I have a list of servers, and then another list of services on each of those servers. I am trying to remove it, change a few values in the .bat and then install the services again. Right now I have started a remote Powershell Session…
1
vote
1 answer

Invoke-Command is giving NativeCommandError

I am using Invoke-Command { & "powershell.exe" } -NoNewScope and getting error as belove. powershell.exe : Loading personal and system profiles took 1761ms. At line:1 char:18 + Invoke-Command { & "powershell.exe" } -NoNewScope + …
1
vote
2 answers

Using Splat in Invoke-Command AND passing arguments relevant to the machine

I'm using Invoke-Command, but this question can be relevant to any command using splat. I essentially want to pass two sets of variables that will be useful in the splat command, but I'm not sure how I can do this. In the code below, the…
1
vote
1 answer

Invoke-Command one to Many without timeouts

I am trying to run series of commands on remote Windows Servers. Some of these servers are up and some of them not. To some I have access and to some of them I do not have access. Options to address this: I can go with: $Computername = PC1, PC2, PC3…
aster007
  • 335
  • 2
  • 13
1
vote
0 answers

Powershell Execute exe on VM remotely

I've searched and tried different variations of commands, but none seems to work for me. I believe I have also gone through all the SO references on this. Tried all the ways here:…
Raj
  • 199
  • 1
  • 12
1
vote
0 answers

Remotely connect to a device to invoke-command using local admin credentials instead of domain authentication

I need to access a remote device to run commands, but they need to be run as the local admin account. Whenever I use Get-Credential, I have to authenticate over the domain, which of course fails if I provide a .\LocalAdmin format. Is there a way to…
David Metcalfe
  • 2,237
  • 1
  • 31
  • 44
1
vote
1 answer

Invoke-Command not finding script, but it's there

I'm attempting to run a very simple script on a different server and am getting an ItemNotFoundException. Here's my script: Invoke-Command -ComputerName myserver -FilePath C:\laurietest\testthis.ps1 Invoke-Command -ComputerName myserver …
Laurie Dickinson
  • 796
  • 1
  • 10
  • 21
1
vote
2 answers

Powershell invoke-command ArgumentList with optional argument

I have a function that works with the invoke-command function either without any arguments or with all arguments. What I would like to do is run the function via invoke-command with only 1 argument. Here is my code function remove-oldfiles { param…
ccaj
  • 25
  • 6
1
vote
1 answer

PowerShell slow Invoke-Command

I'm writing a PowerShell-Script that reads all shares from all AD-Servers and outputs them into a csv-file. At the same time the script is saving all occuring errors and outputs them into an error-log. Can you guys see any possibility that could…
zynory
  • 43
  • 3
1
vote
1 answer

Exporting Powershell REST API results as CSV

I'm currently use the following Powershell script as an API call using REST to retrieve table data from a vendor, which appears to be in JSON format: $uri = "https://www.SomeWebsite.com/api/orders" $headers = @{ 'Content-Type' =…
Depth of Field
  • 307
  • 2
  • 16
1
vote
2 answers

PowerShell Add Parameters to Command / For-Each?

So, I'm in PowerShell and I can run a command like... & .\curl.exe -vk -u -F -F --url That all works fine, but sometimes there are more data entries to add, so more "-F"s to add. Like... &…
Neil
  • 41
  • 4
1
vote
1 answer

An error has occurred which Windows PowerShell cannot handle

When i'm trying to do remote connection using invoke command icm -cn $ips -Credential $crd {hostname} i'm getting error as An error has occurred which Windows PowerShell cannot handle. A remote session might have ended.
Srishti
  • 13
  • 3
1
vote
0 answers

Can't get OperationTimeout to work with New-PsSession

Please help, this feels so trivial yet I have been trying innumerous variations - to no avail. I have been trying to get the OperationTimeout parameter to work when opening a powershell remote session using New-PsSession. Forget all the samples I…
Veverke
  • 9,208
  • 4
  • 51
  • 95