English 中文(简体)
远程计算机成像
原标题:Execute Start-Process Powershell Script on a Remote Computer

我将PowerShell作为行政管理机构,并使用以下的编码线,为更新窗户开户。 罚款

Start-Process  wusa.exe  -ArgumentList  C:Tempwindows10.0-kb5032189-x64_0a3b690ba3fa6cd69a2b0f989f273cfeadba745f.msu  -verb runas

但是,现在,我正试图以某种方式利用这部法典,在遥远的电脑上操作档案。 窗户更新档案的名称和偏远个人电脑的确切位置相同。

I came up with this code below which first gets admin credentials and passes it to the the invoke-command. Then the invoke-command runs the Start-Process code.

$Username =  username123 
$Password =  84fWfghnsf&5Fh 
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Invoke-Command -ComputerName 8HPF31J7V6.domain.local -Credential $Cred -ScriptBlock {Start-Process  wusa.exe  -ArgumentList  C:Tempwindows10.0-kb5032189-x64_0a3b690ba3fa6cd69a2b0f989f273cfeadba745f.msu  -verb runas}

问题在于,当我这样做时,遥远的《刑法》没有发生。

I also don t get any errors when running

“在此处的影像描述”/</a

任何关于我做什么错误的想法,或除此以外的任何其他解决办法?

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm


因此,<><>>> ∗∗>

# ... credential construction code ($Cred) omitted
# Note: If the *current user* is allowed to make remoting calls,
#       you may not need to construct credentials and don t need the 
#       -Credential parameter below.

# Note the use of -Wait, removal of -Verb RunAs
Invoke-Command -ComputerName 8HPF31J7V6.domain.local -Credential $Cred -ScriptBlock {
  Start-Process -Wait wusa.exe -ArgumentList  C:Tempwindows10.0-kb5032189-x64_0a3b690ba3fa6cd69a2b0f989f273cfeadba745f.msu 
}

Read on for an asynchronous alternative. Note that the (Start-Process -PassThru …).ExitCode technique shown below, for reporting the remote process exit code, can equally be used with the synchronous approach above.


<<><>Asynchronouslement:>

www.un.org/Depts/DGACM/index_spanish.htm 如果您不希望<代码>。 Invoke-Command 呼吁等待遥控发射过程(wusa.exe)终止。

www.un.org/Depts/DGACM/index_spanish.htm 附有<代码>-AsJob的同步变量<>/strong>,其中进一步显示如何报告遥远过程exit代码:

# ... credential construction code omitted

# Note the use of -AsJob and the use of -PassThru with Start-Process
# so as to be able to report the process  exit code.
$remoteJob = 
  Invoke-Command -AsJob -ComputerName 8HPF31J7V6.domain.local -Credential $Cred -ScriptBlock {
    (
      Start-Process -Wait -PassThru wusa.exe -ArgumentList  C:Tempwindows10.0-kb5032189-x64_0a3b690ba3fa6cd69a2b0f989f273cfeadba745f.msu 
    ).ExitCode
  }

# ... perform foreground activity here.

# Now wait for the remote job to complete - which happens when 
# wusa.exe terminates - and report its exit code.
$exitCode = 
  $remoteJob | Receive-Job -Wait -AutoRemoveJob 
问题回答

暂无回答




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...