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

Powershell variable is not transfering correctly in the Invoke-Command

I'm writing a script where in one part I want to export some settings of the SCVMM VM and set it in another. I have to run it from another machine, which doesn't have SCVMM installed so I have to call our VMM with Invoke-Command. Unfortunately,…
Niaz
  • 11
  • 1
1
vote
1 answer

Invoke-Command with static password

I want to execute a script that requires privileges on a remote Windows Server machine , but each time i execute the script a pop-up window appears in order to type the password, so how can I add the password as a static parameter into the command…
MKH_Cerbebrus
  • 51
  • 2
  • 10
1
vote
1 answer

Character-encoding problem with string literal in source code

$logstring = Invoke-Command -ComputerName $filesServer -ScriptBlock { param( $logstring, $grp ) $Klassenbuchordner = "KB " + $grp.Gruppe $Gruppenordner = $grp.Gruppe $share = $grp.Gruppe …
1
vote
1 answer

Invoke remote .exe on server with argument list

I'm quite new to PowerShell and I'm hoping to ask a question about a command I'm attempting to run. I've read and read everything I can find on this so apologies in advance if I'm asking the impossible or something dumb. From the Windows CLI on the…
1
vote
1 answer

Powershell invoke-command $input

I have a trouble.. Can someone help me? Here is my Code : $A = '123' $servers = 'computer1' $Properties = [ordered]@{A = $A servers = $servers } $MyObject = New-Object -TypeName PSObject…
1
vote
1 answer

Remotely reboot computer twice

I have a scenario where I need to reboot a computer twice, remotely. My command: Invoke-Command -ComputerName $computerName -Credential $cred -ScriptBlock { workflow Reboot { Restart-Computer -Wait Restart-Computer -Wait …
Tobias KKS
  • 130
  • 1
  • 4
  • 17
1
vote
1 answer

Can't seem to do a Function.Invoke with multiple parameters in powershell?

I'm trying to pass a function to a method and then pass parameters to the method I passed when calling it, but if I pass more than one parameter then the method fails with an error: function debugMeStuffs($someBlah, $somePoo) { Write-Host…
leeand00
  • 25,510
  • 39
  • 140
  • 297
1
vote
1 answer

convert curl command to invoke-WebRequest or Invoke-RestMethod

I have a requirement to convert a working curl command to Invoke-WebRequest command The command is used to create a project in SonarQube Curl: curl -u as123123112312: -X POST…
Krishh
  • 103
  • 1
  • 8
1
vote
0 answers

How to send data using REST in PowerShell

I'm trying to send a file to a wiki (it's in VSTS using git) through a REST api call in PowerShell. What I have currently is: Invoke-RestMethod -Method Put -Uri $uri -ContentType 'application/json' -headers $header The error I get…
iask
  • 11
  • 2
1
vote
1 answer

Running WinRM quickconfig for remote servers

I am writing a PowerShell script that reads in a list of hosts from a file. I have tried two separate methods, having issues with both. First Method: $WinRM = Invoke-Command -Computer $server -ScriptBlock { WinRM quickconfig } This gives the…
Kilik
  • 53
  • 1
  • 5
1
vote
2 answers

Trying to add PSCustomObjects to an ArrayList on a remote machine

I have some experience with PowerShell, and usually Google or searching forums like these yields the answers when I have questions - but not this time. I'm trying to collect the number of .log files in a directory on a remote server, then I'd like…
1
vote
0 answers

Invoke-command with script return blank data

I follow a powershell for penetration testing course and I must use Invoke-command to remotely find words like password, username, credentials in txt file so i make this script called juicyinfo.ps1 Get-ChildItem -Path…
1
vote
2 answers

Concatenate powershell commands

I'd like to run this commands in 1 line: $url = "https://githubxxxx/install.ps1" $webClient = New-Object System.Net.WebClient $webClient.Proxy = [System.Net.GlobalProxySelection]::GetEmptyWebProxy() $webClient.DownloadString($url) |…
Badb0y
  • 331
  • 2
  • 21
1
vote
1 answer

Using invoke command to create com object on a remote system

This command is used to get the status of Microsoft update. In my environment it is set to never check for updates. $WUSettings = (New-Object -Com "Microsoft.Update.AutoUpdate").Settings But I want to run this command on remote computer. I am…
1
vote
1 answer

variable in function executed by invoke-command not visible

Can someone please help me get the below code to work? $ab = "1" function test { $script:ab = "c" } invoke-command -ComputerName localhost ${function:test} $ab After running the above function by invoke-command I want to see value "c" for $ab
Rudixx
  • 105
  • 1
  • 1
  • 7