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

Using chocolatey and invoke-command on a remote share

I am trying to use invoke-command to install some chocolatey packages. When the files are embedded in the chocolatey package, it works without problems. However, when I try to specify a share on a remote server and even opening it in read/write for…
Axiom
  • 33
  • 1
  • 8
1
vote
1 answer

InvokeCommandAction won't work when used in an EventTrigger?

this is my first question on stack-overflow so please be gentle :-) In one of my WPF windows I have a listbox whose items are templated with the following data template:
desfen
  • 11
  • 1
  • 3
1
vote
0 answers

Invoke-ASCmd to Deploy from Json File throws Error - Using Powershell and Azure Analysis Services with OAuth and Azure Data Lake

Summary: I am using Invoke-ASCmd –InputFile "$templateLocation" -Server $serverName on PowerShell to deploy a model/table to Azure Analysis Services (AAS) server. The problem is that I get the error "Invoke-ASCmd : Index was outside the bounds of…
1
vote
1 answer

ADInvalidCredentialException with PowerShell remote management for Exchange 2010

(My English is bad) Hi Techies, I am trying to get Mailbox statistics using Remote PowerShell with cmd executed as an Administrator. powershell -command "$session=New-PSSession -ComputerName 'EX2' -Credential $cred; invoke-command -Session $session…
1
vote
1 answer

Invoke-command not returning any value when get-itemproperty return null

I'm attempting to use the builtin parallel processing capabilities of Invoke-Command so I can quickly scan hundreds of machines for Office 365 installations (finding discrepancies in SCCM reporting). However, when Get-ItemProperty can't find the…
1
vote
0 answers

Cannot create permanent mapped network drive that can be access through File Explorer from host Powershell Invoke-command

I was trying to create a mapped network drive in my Windows 10 Hyper-V VM through an "Invoke-Command" from my host. PS C:\Users\YChan14\Desktop> $session = New-PSSession -VMName "Win10" -Credential $mycreds -Name "NetworkDriveMapping" PS…
terryxychan
  • 23
  • 1
  • 5
1
vote
1 answer

Invoke-Command takes a long time, but only occasionally

I have a PowerShell script using Invoke-Command that has been in use for about a year that suddenly has been having very bad performance issues. What normally took 1 to 2 seconds to run now takes about 90 seconds. Confusingly, it doesn't always take…
justanotherguy
  • 506
  • 2
  • 4
  • 18
1
vote
0 answers

Running a Powershell Script inside of an PSSession with Invoke-Command

So I have a "Parent" Script, that does an invoke-command to some web servers, and inside of that invoke-command, I have a "Child" script that is removing and copying some files. Here's the Parent script: (note: The $cred variable is a verified and…
1
vote
0 answers

remote execution of powershell script that copies files, getting unauthorized access

So I have a Powershell script that reads a csv file that copies files from one remote directory to another. script runs script copies files from a directory on serverA to a directory on serverB. So currently I invoke a remote command from ServerC…
user2026989
  • 11
  • 1
  • 4
1
vote
1 answer

Passing a cmd-line IF statement through Invoke-Expression breaks on output

If I pass an IF statement through PowerShell's Invoke-Expression, the command appears to be running and completing, but then it appears that the output is being evaluated as a new command instead of being returned to PowerShell. Three…
justanotherguy
  • 506
  • 2
  • 4
  • 18
1
vote
1 answer

PowerShell workflow Invoke-Command not working (Write-Host)

Currently trying to use PowerShell workflow to process some remote server stuff that I am doing in parallel. I am having no luck trying to get the Invoke-Command to log onto the server to actually work. It is not throwing an error but there also is…
1
vote
0 answers

Background jobs stops after a few minutes

See below a simplified version of my PowerShell code. $cred = Import-Clixml d:\cred.xml Invoke-Command -ComputerName $computer -Authentication Credssp -Credential $cred -InDisconnectedSession -SessionOption…
JET
  • 11
  • 1
1
vote
2 answers

Need help to pass and execute Function with arguments into of a Scriptblock to execute it remotely

I am writing an application that uses a function to handle data manupilation. At this point I need to execute a scriptblock on the remote computer that uses this function and receves it as a parameter. The code I am testing accomplishes this, but it…
1
vote
1 answer

Impossible to convert System.Object[] into type {System.String, System.Management.Automation.ScriptBlock}

When I use Invoke-command in Powershell, Select-object generates an error on the program. $pc='server1','server2' $csv = "\\mypc\c$\Users\me\Desktop\Script\PC2\Length.csv" $command=Get-ChildItem -Path C:\Users -Exclude C:\Users\*\AppData -Recurse…
1
vote
1 answer

Script to append records as found or in batches from Invoke-Command

I'm fairly new to powershell. The below is my attempt to return records of software on a list of systems via invoke-command. It does work. However, it seems like all results are stored in memory and then exported to the CSV all at once. Instead, I'd…
J T
  • 59
  • 2
  • 6