Powershell:使用 Notepad++ 的启动进程进行脚本化远程安装无限期挂起

问题描述 投票:0回答:3

我编写了一个脚本,它采用带有易受攻击的服务器的 csv 文件,并且应该替换已安装的 Notepad++ 版本。 我从机器上卸载当前安装的版本,将安装程序推送到机器的 C:\ 目录中,然后将其删除,效果完全正常。 我还验证了安装程序的推送是否有效,我在计算机上拥有管理员权限,并且我使用的帐户是(域)管理员帐户。 然而,当我尝试安装提供的 .exe 时,我的问题就开始了: 脚本此时陷入困境。没有任何相关错误,也没有提示,此时什么也没有发生。使用 RDP 登录计算机时,似乎什么也没有发生,也没有安装过程开始。没有创建任何文件夹,也没有移动任何文件或任何内容。

这是我脚本的相关部分:

    Write-Host "push installer"
    Copy-Item $installerUrl -Destination "\\$serverName\C$"

    Write-Host "set path"
    $installerPfad = "\\$serverName\c$\npp.8.5.6.Installer.x64.exe"
    

    Invoke-Command -Session $session -ScriptBlock {
        param ($path, $cred)
        # Returns $true if elevated, otherwise $false.
        [Security.Principal.WindowsPrincipal]::new(
            [Security.Principal.WindowsIdentity]::GetCurrent()
            ).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
        whoami #The user gets recognized correctly and is domain admin
        if (Test-Path -Path $path) {
            Write-Host "$path ist erreichbar."
        } else {
            Write-Host "$path ist nicht erreichbar."
        }
        Start-Process -FilePath $path -WorkingDirectory $env:TEMP -ArgumentList "/S, /D=C:\Program Files\Notepad++" -Wait 
    } -ArgumentList $installerPfad, $credentials
    #$Error[0]
    #$Error[0].Stacktrace

我有一点担心,安装程序会提示类似uac的东西,但我既不能确认也不能否认。以这种方式开始安装会触发 UAC 横幅吗?

您能帮我确定问题并解决它吗,因为我已经花了两天时间来解决这个问题,但我找不到问题。 谢谢

-我尝试过:-

显然我希望安装能够正常工作,这也不应该花那么长时间,因为它是一个非常小的程序。 我尝试过的:

  • 传递 -Verb RunAs,这显然不能远程工作,也不需要它,因为我验证了提升的权限

  • 将我的凭据传递给 dom 管理员,这奇怪地创建了权限被拒绝的错误,但这在这里也应该无关紧要,因为我的帐户已提升

  • 删除 /D=... 参数

  • 将 /S 参数写为 /s

  • 省略 -WorkingDirectory 参数

  • 检查相关内容的$Error

powershell installation notepad++ invoke-command start-process
3个回答
0
投票
     Write-Host "push installer"
Copy-Item $installerUrl -Destination "\\$serverName\C$"

Write-Host "set path"
$installerPfad = "\\$serverName\c$"

Invoke-Command -ComputerName "Computer1" -ScriptBlock {
    param ($path)
if (Test-Path -Path $path) {
        Write-Host "$path ist erreichbar."
         start-process -FilePath "$Path\npp.7.5.6.Installer.x64.exe" -ArgumentList '/S' -Verb runas -Wait
    } else {
        Write-Host "$path ist nicht erreichbar."
    }

}-ArgumentList $installerPfad

0
投票

我实际上可以重现您使用悬挂装置时的行为。不管怎样,下面的代码就起作用了:

$Computername = 'remoteComputer'
$InstallerLocalPath = 'C:\Temp\npp.8.5.6.Installer.x64.exe'
$UNCTargetPath = '\\{0}\c$\Temp' -f $Computername
if (-not (Test-Path -Path $UNCTargetPath)) {
    New-Item -Path $UNCTargetPath -ItemType Directory |
        Out-Null
}
Copy-Item -Path $InstallerLocalPath -Destination $UNCTargetPath

$PSSession = New-PSSession -ComputerName $Computername
Invoke-Command -Session $PSSession -ScriptBlock {
    & $Using:InstallerLocalPath '/S'
}

顺便说一句:我使用远程计算机管理员组成员的帐户来运行代码。


0
投票

大家好,非常感谢大家的回复。 进一步的调查似乎表明,我的一些服务器将 UNC 路径解释为某种“糟糕的狂野西部互联网区域”,因此发起了一个额外的请求,以确定该文件是否可信。将远程调用的命令更改为绝对路径几乎解决了问题。 接受我的第一次补丁运行并使用更新路径版本 8.5.6 的 15 台机器在第一次尝试时无法执行静默运行并冻结,但在几个小时后以某种方式恢复并确实按预期执行了升级,所以我不得不将此视为“抖动”。 所以我的疯狂猜测是主要问题是使用 UNC 路径触发安装。 问候 Poweruser181

© www.soinside.com 2019 - 2024. All rights reserved.