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

Invoke method CsSCript Notepad++

I have this simple method CallMethod made in Notepad++ with CsScript. How to invoke in from VS ? namespace TestCall { using System; using System.Collections.Generic; using System.Linq; using System.Text; using…
1
vote
0 answers

PowerShell - Remote Upgrade Script

I am trying to upgrade Powershell on a bunch of Windows 7 boxes so I can do other remote installs and such. I am using Invoke-Expression but I swear this worked once before without it. There doesn't appear to be a Wait option for any of this. It…
1
vote
1 answer

Remotely Set-Printer Options

I'm working on a script to set the different printer settings (share, publish, duplex, etc...) with PowerShell. In my environment, I have a different account for server access versus my workstation. So I'm trying to pass those elevated permissions…
Dalebert
  • 35
  • 4
1
vote
1 answer

Invoke-Command Doesn't Run with Parameters

I'm trying to run Invoke-Command within a PowerShell script to run scripts on remote servers. It retrieves the computer names and scripts to run from an XML file. Code sample is below. The script executes but nothing on the remote server is being…
UltraJ
  • 467
  • 1
  • 10
  • 20
1
vote
4 answers

Using Invoke-Command with Variables in ScriptBlock

New to PowerShell and learning through writing random scripts using the help info. I've tried the following 3 ways to properly get variables into the ScriptBlock(along with way too many small variations to list) with listed error message wrapped in…
1
vote
0 answers

Invoke-command returns inconsistent values

I don't understand why this won't work and if someone could explain better for me? What I want to do is check winmgmt on all servers but it doesn't seem to work with invoke-command because the script runs so quickly, compared to the half…
James
  • 303
  • 2
  • 12
1
vote
1 answer

Use variable from script inside of scriptblock

I am trying to write a Powershell script that will logoff a currently logged in user. I am using the Invoke-Command cmdlet with a scriptblock inside of the script. I defined some parameters in the script that I am trying to pass to the script block…
Noct03
  • 37
  • 1
  • 7
1
vote
1 answer

Using PowerShell to verify that a specific service exists from a .txt list of server names

I am trying to verify that a specific service exists from a .txt list of server names and then output to a file. In this case I need to also add credentials so I need to use the Invoke-Command. What am I doing wrong here? clear start-transcript…
1
vote
0 answers

Powershell Invoke-Command not grabbing clipboard data with Get-Clipboard

I've lost a handful of hair today trying to figure out the best way to grab the data from the clipboard on a remote server. I thought simply: $cred = New-Object System.Management.Automation.PSCredential('USERNAME', $password); Invoke-Command…
Mike
  • 29
  • 6
1
vote
0 answers

How do you log the results of remotely invoked commands on the system running the PowerShell session?

I have a script that loops through a list of my servers, and runs various commands on them. I am attempting to log the commands and their results for both the computer running the PowerShell script, and the remote computer running the…
1
vote
0 answers

Remote Get-ChildItem Return Value is wrong

I'm trying to list user profiles' sizes on remote computers combining Invoke-Command & Get-ChildItem, but there's an issue I can't figure out : When I launch the command locally : PS> (gci -recurse -force "C:\Users\user1" -File -ErrorAction…
Daycopo
  • 188
  • 1
  • 1
  • 11
1
vote
1 answer

Invoke-Command fails with $env Variable fails when configuration is read from a file

I am trying to retrieve files from a remote system via PowerShell. In order to do this i utilize New- PSSession and Invoke-Command in this session. $latestFolder = Invoke-Command -Session $remoteSession -ScriptBlock{param($path) Get-ChildItem $path…
xBarns
  • 291
  • 1
  • 3
  • 12
1
vote
1 answer

Storing encrypted password Powershell

I am having challenge with one of my Powershell scripts. The idea is to run a tool from a client, which will kill some processes using the PID. Proof of concept works - ps1 script is converted to exe (PS2GUI) and the tool is successfully killing the…
Nikec123
  • 39
  • 6
1
vote
1 answer

Can't Get Screen Resolutions from Remote Computers via PowerShell Remoting

I'm trying to get correct screen resolutions from remote computers using Invoke-Command and a PSSession but both methods report one resolution of 1024 x 768. There are two screens, 1920 x 1080 and 1280 x 720. This is not a DPI thing. Executing the…
1
vote
2 answers

Call .py script from deployment package(added as a layer)in AWS lambda using python

I have added a zip file as an deployment package which includes an xxx.py script. My lambda function should invoke xxx.py script from the package. My lambda function as below: libdir = os.path.join(os.getcwd(), 'local', 'lib') download_path =…
R S
  • 21
  • 2