0

I have written a script, that takes a csv file with vulnerable Servers and should replace the installed version of Notepad++. I uninstall the currently installed version from the machine, push a installer into the C:\ Directory of the machine and afterwards remove it, which works totally fine. I also have verified, that the push of the installer works, that I have admin rights on the machine and that the account I use is an (domain) admin account. However, my problems start as soon as I try to install the provided .exe: The script gets stuck at this point. There aren't any relevant errors and no prompts, just nothing happens at this point. When logging into the machine with RDP it seems like nothing happens and no installation process commences. No folders are being created and no files are moved or whatsoever.

This is the relevant part of my script:

    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

I have the slight fear, that the installer is prompting something like the uac, but I can neither confirm nor deny it. Would starting an installation this way trigger a UAC banner?

Can you please help me determine the problem and fixing it as I have spent two days on this now and I can't find the issue. Thanks

-What I've tried:-

Obviously I was expecting the installation to work, which shouldn't take that long too, as it's a quite tiny program. What I tried:

  • passing -Verb RunAs, which apparently doesn't work remotely nor is it needed as I verified elevated rights

  • passing my credentials to the dom admin, which oddly creates a permission denied error, however this should be irrelevant here too, as my account is elevated

  • removing the /D=... argument

  • writing the /S argument as /s

  • omitting the -WorkingDirectory argument

  • checking the $Error for relevant content

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    1. If you're remoting into another computer you usually use an account with administrative rights to this remote computer. So you don't need to check. 2. If you remote into another computer you cannot remote into a third computer from there. That's the so called 2nd-hop-issue. You may copy the needed installation sources to your remote computer and run it *locally*. ;-) – Olaf Sep 01 '23 at 10:10
  • @Olaf I didnt intend to remote into a third computer from there, did I do that? However, I successfully copied my installer to remoteComputer\C:\ but installing it remote to that computer fails without an output. if i log into said remote computer and execute the exact same script there, it runs successfully, but triggers and UAC splashscreen. How do I remotely install it (and circumvent possible UAC prompts? – poweruser181 Sep 01 '23 at 11:37
  • @mklement0 I was referring to npps unattended installation guide https://npp-user-manual.org/docs/command-prompt/#installer-options however if I completely remove the /D... argument, the behaviour stays the same – poweruser181 Sep 01 '23 at 12:18
  • Thanks, @poweruser181 - the `/D` syntax is truly bizarre; to spell out what your link says: quoting _must not be used_, even if the path contains spaces; therefore, to avoid ambiguity, the `/D` option must come _last_ on the command line. However, there's still a problem with your `-ArgumentList` value: the `,` shouldn't be there, given that you're passing a _single string_: -> `-ArgumentList "/S /D=C:\Program Files\Notepad++"` - not sure if that completely solves the problem. – mklement0 Sep 01 '23 at 12:23
  • You can also check the exit code to see if it provides a clue as to what goes wrong: `$exitCode = (Start-Process -FilePath $path -WorkingDirectory $env:TEMP -ArgumentList "/S /D=C:\Program Files\Notepad++" -Wait -PassThru).ExitCode` – mklement0 Sep 01 '23 at 12:26

2 Answers2

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
Narayana Lvsl
  • 315
  • 2
  • 10
0

I actually could reproduce the behaviour you had with the hanging installation. Anyway the following code just worked:

$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'
}

BTW: I used an account beeing member of the administrators group of the remote computer to run the code.

Olaf
  • 4,690
  • 2
  • 15
  • 23
  • If the installer is a GUI-subsystem application (as they typically are), invocation with `&` will run asynchronously and therefore relies on the `$PSSession` session to stay alive long enough for the installation to finish. Is it the `-Wait` switch passed to `Start-Process` that causes the hang? – mklement0 Sep 01 '23 at 19:49
  • 1
    @mklement0 Even without the `-Wait` switch the `Start-Process` hangs. It does not even seem to start the installation at all. While the installation called with the call operator `&` works without any issue. `¯\_(ツ)_/¯` – Olaf Sep 01 '23 at 21:23