Powershel Get Elevated process ExitCode

Mohammed Faisal 0 Reputation points
2023-05-21T09:52:26.7733333+00:00
I am trying to install an application silently but I could not get the proper exit code since I am running with elevated privilege.
Note $Credential trying to install with another local user with admin privilages. Please advice on this.


$tab = "C:\Tab Server"
$tab = "D:\TabInstaller\TabServer-64bit.exe"
$tablog = "C:\Temp\Tableaulog\TabInstaller.log"

$list = "-noprofile -command ""Start-Process cmd.exe -Verb RunAs -ArgumentList '/c ""$tab"" /silent /install ACCEPTEULA=1 ACTIVATIONSERVICE=0 """"""INSTALLDIR=$($drive)"""""" ""/log $tablog""'"""

[int]$result = (Start-Process "powershell.exe" -Credential $credential -ArgumentList $list -NoNewWindow -Wait -Passthru).ExitCode
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,309 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points
    2023-05-21T18:17:44.1766667+00:00

    Have you tried it this way?

    $tab = "C:\Tab Server"
    $tab = "D:\TabInstaller\TabServer-64bit.exe"
    $tablog = "C:\Temp\Tableaulog\TabInstaller.log"
    
    $list = "-noprofile -command ""Start-Process cmd.exe -Verb RunAs -ArgumentList '/c ""$tab"" /silent /install ACCEPTEULA=1 ACTIVATIONSERVICE=0 """"""INSTALLDIR=$($drive)"""""" ""/log $tablog""'"""
    
    $proc = Start-Process "powershell.exe" -Credential $credential -ArgumentList $list -NoNewWindow -Wait -Passthru
    if ($proc.ExitCode . . . ){
        # do something
    }
    
    0 comments No comments

  2. Limitless Technology 44,101 Reputation points
    2023-05-23T11:35:56.8366667+00:00

    Hello there,

    You may try to get the process first to understand why the silent installation is not getting proper exit.

    Get-Process | Add-Member -Name Elevated -MemberType ScriptProperty -Value {if ($this.Name -in @('Idle','System')) {$null} else {-not $this.Path -and -not $this.Handle} } -PassThru |

    Format-Table Name,Elevated

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--