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
1 answer

Change mouse location of remote computer using powerhsell?

I am writing a script to change the location of the mouse of a remote computer. The computer or computers would be on the same LAN and per GPO have remote PS sessions/commands enabled. I have it working on my computer but when I try to run it…
Darin
  • 1
  • 1
0
votes
1 answer

Powershell - Passing multiple arraylists to Invoke-Command block

I am trying to write a powershell script that will tell me if a computer in my network is on or off, and if it is on, if there is anyone logged in. Currently I have: # Create some empty arraylists …
jjia
  • 3
  • 1
0
votes
1 answer

PowerShell Invoke-Command on an advanced function

I have an advanced function Copy-FilesHC that is available in a module file. This function copies some files from the Source to the Destination folder and generates some output for in a log file. The function works fine locally: Copy-FilesHC -Source…
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
0
votes
1 answer

How to run Invoke-Command in chunks?

I want to run Invoke-Command on hundreds of servers. It chokes when trying to run them asynchronously, so I want to run them in chunks. How can I tell powershell to launch only X servers in each go?
iTayb
  • 12,373
  • 24
  • 81
  • 135
0
votes
1 answer

Access is Denied when Reset-ComputerMachinePassword is run through Invoke-command

I'm using the following command to reset a remote machine' s password. $user="Domain\domainadmin"; $pass="dapassword" | ConvertTo-SecureString -AsPlainText -Force; $creds=New-Object System.Management.Automation.PSCredential -ArgumentList $UserName,…
Onewildgamer
  • 101
  • 1
  • 2
  • 11
0
votes
2 answers

Powershell script that calls a variable inside of a file path?

Whenever creating an FTP folder for an FTP client in my company, I have to create two folders on two servers; server A and server B. I've tried to give an example below. E:\FTP\CompanyName E:\FTP\CompanyName\Incoming E:\FTP\CompanyName\Outgoing It…
MisterPuggles
  • 133
  • 1
  • 4
  • 18
0
votes
1 answer

Invoke-Expression Not Running Command

I am pulling in a text file that was previously created that simply lists the KB numbers for all currently installed Windows Updates. I am trying to pull this file in and call wusa.exe and pass it the KB number to perform an uninstallation. $a =…
spickles
  • 635
  • 1
  • 12
  • 21
0
votes
2 answers

Import only select data from json to powershell

I want to Import selected data from Json url and so I can convert it to XML. I am using following code to import. (Invoke-RestMethod -URI…
user206168
  • 1,015
  • 5
  • 20
  • 40
0
votes
1 answer

Powershell Invoke-Command query

I'm scripting a task to remotely restart some server application pools periodically. I'm using Invoke-Command as follows: Invoke-Command -ComputerName $server {Restart-WebItem "IIS:\AppPools\DefaultAppPool"} and this works just fine; however, if I…
Kevin Roche
  • 367
  • 1
  • 11
0
votes
1 answer

Not able to get instance-id from powershell in EC2 windows machin

I can able to get the instance-id from AWS EC2 windows machine's IE browser using the URL http://169.254.169.254/latest/meta-data/instance-id In the same machine when I use Powershell command Invoke-WebRequest…
0
votes
1 answer

Is return code required for Invoke-Command

Powershell script Enables PSRemoting on a remote computer Executes setup.exe on a remote computer Disables PSRemoting on a remote computer How can I be sure that I am disabling PSRemoting after the remote computer is able to execute setup.exe? Am…
Glowie
  • 2,271
  • 21
  • 60
  • 104
0
votes
1 answer

Using Invoke-Command within a function

I have this code snippet. The idea is calling an invoke command on a remote pc, but if the command fails, then it should retry. The code looks like this: Function Run-Command { param( [Parameter(Mandatory = $true)] [Uri[]]…
M.frank
  • 145
  • 2
  • 14
0
votes
1 answer

PowerShell Invoke-Command fails to load dll

I saw other posts but none that helped me. Please help. I ran the following cmdlet from my local Win7 desktop having PowerShell4 on it. Invoke-Command -ComputerName COMPUTER123 -ScriptBlock { Import-Module '\\mycomany.com\PS\Task.SQL.psd1'} I got…
SamDevx
  • 2,268
  • 4
  • 32
  • 47
0
votes
1 answer

Powershell Use Invoke-Command Session to Get-Childitem sizes on a remote computer

I am trying to use powershell to remotely access a computer and get the size of each sub-directory of a folder. I am using the script to get each of the folder sizes and it works successfully: $log = "F:\logfile.txt" $startFolder = "C:\" $colItems…
user1953964
  • 11
  • 1
  • 4
0
votes
2 answers

Passing array to -FilePath parameter in PowerShell

I'm using invoke-command to execute a list of scripts on remote servers. I'm using a variable array to specify the scripts. $Modules = Get-Content "Modules\Modules.txt" $ModulePath = "Modules\" + $Module Invoke-Command server -FilePath $ModulePath…