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
0 answers

How to execute PowerShell script as local admin, but show results on logged-in users desktop?

Here is my scenario: I have several computers all on the same domain. Users authenticate against the domain to log into their workstations. All the local Administrator passwords on the workstations are the same. What I want to do is execute script…
campbell.rw
  • 1,366
  • 12
  • 22
0
votes
1 answer

Zip files remotly using the Powershell extension PSCX

basically I want to do this: foreach ($SERVER_NAME in $SERVER_NAME_LIST) { $SESSION = New-PSSession -ComputerName $SERVER_NAME -Credential $CRED Invoke-Command -Session $SESSION -ScriptBlock { Write-Zip -Path $PATH -OutputPath test.zip…
0
votes
1 answer

Unable to get required information from remote machines using powershell invoke-command

I am developing a tool which uses powershell script to search for new windows updates for the machine. Currently by using the 'invoke-command' i am remotely accessing the various build controllers,virtual machines and hosts and running this…
Mahadev Swamy
  • 131
  • 1
  • 9
0
votes
1 answer

powershell invoke command

I am trying to run the following script on a DC from a server and i keep getting the error Cannot bind parameter 'Identity'. Cannot convert value "1" to type "Microsoft.ActiveDirectory.Management.ADComputer". Error: "Invalid cast from 'System.Char'…
user1221996
  • 127
  • 1
  • 3
  • 6
0
votes
1 answer

Powershell invoking remote script to get farmload (XenApp 4.5)

qfarm /loadI have a problem with remote executing a script. The script invokes a command for cmd qfarm /load and converts the result to PSObjects. function New-qLast() { param ([String] $qName, [String] $qLoad) $qLast = New-Object PSObject …
IronGibbet
  • 45
  • 3
  • 8
0
votes
1 answer

Invoke-command and machine not reachable exception

I am still trying to adjust to powershell after a couple of days playing around with it. I have the following question regarding invoke-command. My scenario is this: I am trying to make use of the invoke-command and its ability to "thread" to…
user79089
  • 23
  • 2
  • 4
-1
votes
1 answer

Powershell Invoke-Expression A parameter cannot be found that matches parameter name = ""

Im trying to invoke a Ps script from antoher script. The scripts are both in the same path. Also the script I'm trying to invoke takes 4 parameters. Whem i execute that file from powershell with the parameters, then it works without errors. But…
Subscaper
  • 232
  • 5
  • 15
-1
votes
1 answer

Running commands as logged on user (remotely)

Thought I would share this quick function I made for myself, feel free to adapt it and improve it according to your needs. Sometimes you want to run commands as the logged on user of a remote computer. As you know, some commands show output for the…
Rakha
  • 1,874
  • 3
  • 26
  • 60
-1
votes
1 answer

Execute bat file to remote client

I am trying to open an HTML file to a client "ClientA" that is locally copied to a folder "C:\1.html" remotely by executing the bellow powershell command $Username = 'username' $Password = 'password' $pass = ConvertTo-SecureString -AsPlainText…
MarkP
  • 23
  • 2
  • 2
  • 5
-1
votes
1 answer

pssession, invoke-command not getting variable

So here's the code I have so far: $computerName = read-host "Enter Computer Name" $IPCName = read-host "Enter IPC Profile name" $uName = read-Host "Enter SU account" $pw = read-host "Password" $pwe = convertto-securestring…
-1
votes
1 answer

Invoke-Command limit?

I try to run a command on about 42 servers, and the script got stuck and failed. When I try to run Invoke-Command on the one of the failed servers, I got: Connecting to remote server $$$$ failed with the following error message : The WSMan service…
Itzik
  • 107
  • 1
  • 3
  • 11
-1
votes
1 answer

Powershell Invoke script block - pass proccess check not just text

How can i get: (works) $Procname = 'notepad' Invoke-Command -ComputerName sandbox -ScriptBlock { if ((Get-Process | Where-Object {$_.Name -eq $Procname}) -eq $null) { Write-Host 'null' -ForegroundColor Red } else { …
madman
  • 27
  • 5
-1
votes
1 answer

PowerShell 'Invoke-Expression' command with single quotation

I am trying to invoke the following the command which contains the single quotation, but I am not able to execute and returns as an error: $expression = $snapshot.properties.activities[1].typeProperties.parameters.rawinputlocation =…
Dipti Mamidala
  • 153
  • 2
  • 10
-1
votes
1 answer

Invoke-Command write file to parent machine

I have a script that connects to a remote machine using Invoke-Command and then runs a script block. This all works fine, however I would like to know if its possible to write a log file on to the parent machine. Due to firewalling on the servers…
steve
  • 5
  • 1
  • 3
-1
votes
1 answer

How to create a scriptblock item that can be used in Invoke-Command command

I would like to run a few lines of code on a remote machine, so I have to use the "Invoke-command" cmdlet to achieve that. The script I want to run is rather long (not just a simple command, but a few loops, conditionals, etc.), so it is not…
FrozenLand
  • 259
  • 1
  • 4
  • 14
1 2 3
36
37