invoke-command

Invoke-Command faster than the command itself?

China☆狼群 提交于 2019-12-18 04:16:30
问题 I was trying to measure some ways to write to files in PowerShell. No question about that but I don't understand why the first Measure-Command statement below takes longer to be executed than the 2nd statement. They are the same but in the second one I write a scriptblock to send to Invoke-Command and in the 1st one I only run the command. All informations about Invoke-Command speed I can find are about remoting. This block takes about 4 seconds: Measure-Command { $stream = [System.IO

Passing array to another script with Invoke-Command

佐手、 提交于 2019-12-17 14:49:56
问题 I'm stuck trying to figure this out. I've seen the other articles and have tried everything, but I'm not getting anywhere. I am trying to pass an array as an argument to another PS script. Here's what I'm trying: $IPArray = Get-Content C:\ListofIps.txt Invoke-Command -Computername $server -Credential $cred -FilePath "C:\script.ps1" -ArgumentList (,$IPArray) The 5 values in $IPArray aren't being passed to the script that I call. Thanks in advance, guys, I really appreciate any help you can

How do I pass variables with the Invoke-Command cmdlet?

心已入冬 提交于 2019-12-17 02:52:10
问题 I have to get Event-Logs from some servers and I don't want to read in the credentials for each server which is found. I've tried to pass my variables by using the ArgumentList parameter but I doesn't work. This is my code: $User = Read-Host -Prompt "Enter Username" $Password = Read-Host -Prompt "Enter Password" -AsSecureString $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

How do I pass variables with the Invoke-Command cmdlet?

半腔热情 提交于 2019-12-17 02:52:06
问题 I have to get Event-Logs from some servers and I don't want to read in the credentials for each server which is found. I've tried to pass my variables by using the ArgumentList parameter but I doesn't work. This is my code: $User = Read-Host -Prompt "Enter Username" $Password = Read-Host -Prompt "Enter Password" -AsSecureString $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

Remotely reboot computer twice

倾然丶 夕夏残阳落幕 提交于 2019-12-13 19:10:01
问题 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 } Reboot } But this returns the error Failed to restart the computer com1 with the following error message: A system shutdown is in progress. + CategoryInfo : OperationStopped: (com1:String) [Restart-Computer], InvalidOperationException + FullyQualifiedErrorId :

Invoke-Command failed: WinRM cannot complete the operation

走远了吗. 提交于 2019-12-13 07:28:02
问题 Using 2 machines, a local and a remote (with an address marked as remoteAddress ), I'm trying to run this on the local machine: Invoke-Command -ComputerName remoteAddress -ScriptBlock { dir c:\ } but I get this error: [remoteAddress] Connecting to remote server remoteAddress failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the

Run .ps1 on remote machine

依然范特西╮ 提交于 2019-12-12 19:08:05
问题 I need to execute powershell script on remote computer with admin privilegies. I have 2 scripts: client and server. When i start client.ps1 i invoke command on server machine but get access error. I get no error if I use simple code in server.ps1 like write-host "hello". server.ps1: Get-service -ComputerName 'client' client.ps1: $ScriptBlockContent = { d:\server.ps1 } $remote=New-PSSession -ComputerName 'server' Invoke-Command $remote -ScriptBlock $ScriptBlockContent 回答1: Your problem is

Invoke-Command with static password

岁酱吖の 提交于 2019-12-11 15:37:39
问题 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 so I can escape typing it each time (the password is fixe and unknown) Here is the code that I wrote Param ( $user ) Invoke-Command -ComputerName 'Server.Admin.6NLG-AD' -FilePath C:\SECnology\Data\Utilities\PS_Block_Internet_Access_GPO.ps1

PowerShell Invoke-Command remotely using a share

自作多情 提交于 2019-12-11 09:22:15
问题 I am trying to install software (.exe) with PowerShell remotely on another computer. I have now: Invoke-Command -Authentication Credssp -Credential $cred -ComputerName "TargetComputer01" -ScriptBlock {Start-Process -FilePath $args[0] -ArgumentList ('/log "{0}" /quiet /norestart' -f $args[1]) -Wait -PassThru -Verb RunAs} -ArgumentList @($Installer, $LogPath) This does not work, no errors, no log file, no installed software. So I have no idea why it is not working. I use Credssp because the

Local or remote execution of powershell script with generic parameters

风流意气都作罢 提交于 2019-12-11 03:22:19
问题 In a development team, I would like to have the same test scripts to be executed locally by a developper or remotely by our test platform. Here is what I would like to use as premises for each script # Test local/remote execution by reading C:\ directory param( [switch] $verbose, [switch] $remote, [string] $ip, [string] $user, [string] $password #Add here script specific parameters ) Write-Host "Command invokation incoming parameter count : " $psboundparameters.count if ($remote) { $Params =