Show-ADTInstallationRestartPrompt -silentrestart help

Hi,

I'm uninstalling VPN module, and I would like the uninstall to be silent if the user is not logged in, then machine to reboot. I have followed the suggestion in these 2 posts below and added `finally{..} block

https://discourse.psappdeploytoolkit.com/t/silent-install-with-restart-and-close-processes-prompt/6906

https://discourse.psappdeploytoolkit.com/t/4-1-7-show-adtinstallationrestartprompt-restart-function-not-working-from-intune/7143

i'm using version 4.1.7

this is the code i added after the try{..}catch{..} block

finally
{
    if (!(Get-Variable -Name mainErrorMessage -ErrorAction Ignore))
    {
        Initialize-ADTModule -ScriptDirectory $PSScriptRoot
        if ($runAsActiveUser -and $script:namUninstalled)
        {
            Start-Sleep -Seconds 30 # allow time for user to see toast notification before restart prompt
            Show-ADTInstallationRestartPrompt -CountdownSeconds 3600 -Title "Please restart your computer" -Subtitle "NAM module has been uninstalled. Restart your computer to complete the process." -WindowLocation TopCenter
            Start-Sleep -Seconds 3630
        }
        else
        {
            Show-ADTInstallationRestartPrompt -SilentRestart 
        }
    }
}

When the user is logged on, they receive a prompt to select uninstall/defer , then a restart prompt appears. This works fine, however when no user is logged on and silent uninstall kicks in but the machine does not restart.

Show-ADTInstallationRestartPrompt -SilentRestart doesn't kick in.

If i replace silent restart command with shutdown -r -t 0 the machine does restart. have i missed something not sure how the user got his to work or does it need an active session?

thanks

In v3.x, it would just reboot if no user is present.

I assume in v4.x it would also just reboot if no user is present.

Oh that brings back memories, installing / uninstalling the Cisco AnyConnect / Secure Client NAM module :laughing:
We did this with PSADT v3.10 previously, supressing the restart until the end of the script

N.B. If you refer to the 1st example I think you are missing -SilentCountdownSeconds 300 from your Show-ADTInstallationRestartPrompt -SilentRestart command, it's probably waiting and doesn't know how long it needs to wait before triggering the restart. :man_shrugging:

This is specifically when it executes in the finally block. The commands works fine, if it's placed somewhere else either in the post uninstall or before close-adtsession

for context this is where it sits.

# Commence the actual deployment operation.
try
{
    # Import any found extensions before proceeding with the deployment.
    Get-ChildItem -LiteralPath $PSScriptRoot -Directory | & {
        process
        {
            if ($_.Name -match 'PSAppDeployToolkit\..+$')
            {
                Get-ChildItem -LiteralPath $_.FullName -Recurse -File | Unblock-File -ErrorAction Ignore
                Import-Module -Name $_.FullName -Force
            }
        }
    }

    # Invoke the deployment and close out the session.
    & "$($adtSession.DeploymentType)-ADTDeployment"
    Close-ADTSession
}
catch
{
    # An unhandled error has been caught.
    $mainErrorMessage = "An unhandled error within [$($MyInvocation.MyCommand.Name)] has occurred.`n$(Resolve-ADTErrorRecord -ErrorRecord $_)"
    Write-ADTLogEntry -Message $mainErrorMessage -Severity 3

    ## Error details hidden from the user by default. Show a simple dialog with full stack trace:
    # Show-ADTDialogBox -Text $mainErrorMessage -Icon Stop -NoWait

    ## Or, a themed dialog with basic error message:
    # Show-ADTInstallationPrompt -Message "$($adtSession.DeploymentType) failed at line $($_.InvocationInfo.ScriptLineNumber), char $($_.InvocationInfo.OffsetInLine):`n$($_.InvocationInfo.Line.Trim())`n`nMessage:`n$($_.Exception.Message)" -ButtonRightText OK -Icon Error -NoWait

    Close-ADTSession -ExitCode 60001
}
finally
{
    if (!(Get-Variable -Name mainErrorMessage -ErrorAction Ignore))
    {
        Initialize-ADTModule -ScriptDirectory $PSScriptRoot
        if ($runAsActiveUser -and $script:namUninstalled)
        {
            Start-Sleep -Seconds 30 # allow time for user to see toast notification before restart prompt
            Show-ADTInstallationRestartPrompt -CountdownSeconds 3600 -Title "Please restart your computer" -Subtitle "NAM has been uninstalled. Restart your computer to complete the process." -WindowLocation TopCenter
            Start-Sleep -Seconds 3630
        }
        else
        {
            Show-ADTInstallationRestartPrompt -SilentRestart 
        }
    }
}

I've tested this locally with psexec and i can't get it to restart hence why i was asking for guidance.

yes :slight_smile:

I've tried Show-ADTInstallationRestartPrompt -SilentRestart -SilentCountdownSeconds 300 still the same. I want it to restart immediately afterwards during silent install hence why -SilentCountdownSeconds was not added.

thanks

if it needs an unattended restart, why not lower the number of seconds it waits to 5 rather than wait 5 minutes (300 seconds)
i.e.

Show-ADTInstallationRestartPrompt -SilentRestart -SilentCountdownSeconds 5

I know it's not very graceful, but we had this to force the restart in our PSADT 3.10 script:

Show-InstallationRestartPrompt -Countdownseconds 905 -CountdownNoHideSeconds 60
Start-Sleep -Seconds 5	#Just In Case
Exit-Script -ExitCode 1641     # 1641 = Hard-Reboot

using psexec i ran Invoke-appdeploytoolkit.exe -deploymenttype uninstall. The restart prompt works fine if a user is logged on. The logic in the finally block is working, they receive a prompt to restart their machine.

if no user is logged on silent install is triggered except the machine is not restarted.

this command in the else statement does not run Show-ADTInstallationRestartPrompt -SilentRestart i have tested with -SilentCountdownSeconds 5 and got the same result.

I think we'd need to see what the PSADT log records at this point for devices where no-one is logged on

appreciate your help. logs are not captured in the finally block I believe because the session is closed.

with regards to providing logs, it was mentioned in this post why the logs will not be captured and i have tested locally as I mentioned earlier.

I've managed to get it working by moving silent restart in the post-uninstallation tasks:

    ## <Perform Post-Uninstallation tasks here>
    if ($uninstallResult.ExitCode -eq 3010) {
        $script:namUninstalled = $true
        if ($runAsActiveUser) {
            try {
                Start-ADTProcessAsUser @processParams # remind users to reconnect to wifi
            }
            catch {
                Write-ADTLogEntry -Message "Toast notification failed to execute"
                continue
            }
        }
        else {
            Show-ADTInstallationRestartPrompt -SilentRestart
        }
    }

I then removed the else statement at the end of the try catch block to only show the restart prompt if user is logged in.

finally
{
    if (!(Get-Variable -Name mainErrorMessage -ErrorAction Ignore))
    {
        Initialize-ADTModule -ScriptDirectory $PSScriptRoot
        if ($runAsActiveUser -and $script:namUninstalled)
        {
            Start-Sleep -Seconds 30 
            Show-ADTInstallationRestartPrompt -CountdownSeconds 3600 -Title "Please restart your computer" -Subtitle "Cisco NAM has been uninstalled. Restart your computer to complete the process." -WindowLocation TopCenter
            Start-Sleep -Seconds 3630
        }
    }
}

I'm probably repeating myself with the code and would be good to get some guidance.