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

powershell invoke-command access denied exception

I have following script to run some basic commands on remote machine and log the output to the share. I'm getting access denied exception on the share even though the share has full control access for everyone including me executing the…
Siva Dasari
  • 1,059
  • 2
  • 19
  • 40
1
vote
1 answer

Powershell different Credentials with encapsulated arguments

after trying several possibilities I'am not sure how to continue. I need to execute a script "C:\test1\script.ps1" And I need to pass some Arguments with this script too. These Arguments (-Hashtag $Hashtag -Name $Name and so on...) are stored in a…
1
vote
1 answer

Install Bluetooth Driver on Remote HP Laptop with Powershell

I am looking to install bluetooth driver to 30 HP Elitebook 840 G3 laptops, and I am looking to do it with Powershell. I can do this locally: Start-Process "C:\\installer\\bluetooth.sp74472.exe" -argumentlist "/s" -wait But I can't seem do this to…
deni_hanca
  • 11
  • 2
1
vote
2 answers

PowerShell Remoting - Invoke-Command not Returning Output

I am running following command remotely from PowerShell in Admin mode. This gets the status of App Pool (in IIS) from remote machine. $result = Invoke-Command -ComputerName $servername -ScriptBlock { param($appPoolName) Get-WebAppPoolState…
Parveen Kumar
  • 419
  • 3
  • 7
  • 20
1
vote
1 answer

Powershell: Null Array Exception in passing args to Remote Session

I am trying to run a command on a remote session but I am getting a Cannot index into a null array. + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray + PSComputerName …
Deepanshu Kalra
  • 419
  • 2
  • 9
  • 23
1
vote
2 answers

Powershell: Remote exe Installation

I'm having problems with my script that is designed to install an executable remotely. All of the preliminary actions of my script work just fine. I grab the host names of about a dozen computers from a text file. I use PSExec to Enable-PSRemoting.…
Jeff Godzilla
  • 119
  • 1
  • 2
  • 6
1
vote
1 answer

execute remote powershell script on remote server

I have looked for weeks, and had others research with/for me, but I haven't found the answer to this. I have a script that lives on server 1, and needs to be executed on server 1 using certain credentials. The ultimate solution will help with…
Glenda Gable
  • 11
  • 1
  • 2
1
vote
2 answers

Is it possible to invoke-command with in a workflow?

Do anyone know if I can use Invoke-Command in a PowerShell workflow? Currently I have script that loops through a text file with the list of services but I would like it push to all of the servers at once verses going through one by one. Is this…
Sheldon Lewis
  • 35
  • 1
  • 5
1
vote
1 answer

Remove part of Powershell Result within Invoke Command

I have the following line: "OSType" = Invoke-Command -ComputerName $Computer -ScriptBlock { Get-CimInstance SoftwareLicensingProduct | Where-Object -FilterScript { ($_.Description -like "W*" -and $_.licensestatus -eq 1 ) } | select-object -first 1…
onefiscus
  • 129
  • 1
  • 3
  • 15
1
vote
2 answers

Invoke-command StackOverFlowException

I'm trying to use Invoke-Command to run a scriptblock on a remote machine. The scriptblock is: $scriptBlock = { echo Y | .\DP.EXE IMPORT $remoteExportDir 'MicrosoftDynamicsAx' $remoteMachine } I run this scriptblock like this: Invoke-Command…
Doug
  • 1,316
  • 6
  • 19
  • 36
1
vote
1 answer

Invoke-WebRequest Leaving Sessions Open

Ive written a script to login to a customers website. Everything works just fine, but they reported back to be that they are seeing stale sessions from the account that I use. I am at a loss for how to fix this as my googlefu is returning nothing.…
Alcaeus
  • 145
  • 3
  • 13
1
vote
0 answers

Execute SSIS package remotely via DTExec: ForEach loop file enumerator is empty

curly one for SSIS / Windows / Powershell people. I have an issue where I have two Windows 2012 servers and I'm trying to remotely execute an SSIS package. Server "D3" is the SQL server database with SSIS installed, and I am able to execute my…
marcus
  • 11
  • 2
1
vote
1 answer

Passing the entirety of the common variables to an invoke-command

Recently I've been downloading powershell functions and scripts that I find useful and wrapping them into invoke-commands to make them more useful across my network. One thing I haven't figured out is how to accept the common parameters from the…
M. Anselmi
  • 21
  • 3
1
vote
1 answer

Powershell: use invoke-command with custom function to execute at remote computer and display output in the host computer

I am struggling with invoke-Command to execute custom function remotely and display the output at the local host. I've read many posts regarding invoke-Command online but I haven't find a way to resolve this problem. First the custom function is…
LeonC
  • 11
  • 3
1
vote
1 answer

Can we execute rightclick without using pCmdInfo->lpVerb

I am not agnaist using pCmdInfo->lpVerb but my problem is how will we handle the situation when we create the rightclick submenus dynamically. For example, I have the following scenario: if(strcmp(cRegKeyVal,"Connected")==0) { …
Simsons
  • 12,295
  • 42
  • 153
  • 269