Hello,
I simply love this tool, it makes the deployment of a variety of applications so much more user friendly.
I am currently using the latest release PSADT v3.9.2
I have been working on creating a fairly simple but bespoke solution for dealing with a minority of users that do not restart their machine after Windows Updates are installed each month, that does not use the Deploy-Application.ps1 script but just makes use of the Show-InstallationRestartPrompt
function but sadly I can not seem to get the Show-InstallationRestartPrompt
to show in the Users context when the script is executed within the System Context (using ServiceUI.exe).
We use Intune to deploy all our applications, but this is the first time Iāve tried using both the Show-InstallationRestartPrompt
and the ServiceUI.exe from an Intune Proactive Remediation (PR).
Background on what I have got so far:
I have a copy of the AppDeployToolkit extracted on a machine to C:\ProgramData\MyCompany\PSADTK
, with some minor customisations to brand the PSADT dialogs with our branding / logo.
I check if a restart is pending (using similar code to this: check-if-reboot-is-pending-windows-10-and-11) and check the Windows System Event Log for EventId 43 (Started) where no corresponding EventId 19 (Successful) exists.
Ultimately the PR should (in the detection script) detect if the machine has started the Windows Update Install, is pending a restart and the Successful Event has not yet appeared in the System Event log. (Meaning it is highly likely the user has not actioned the Windows Update restart prompt) If this criteria is met, I capture the start time from EventId 43 and customise the AppDeployToolKitConfig.xml from a template in the PR detection script.
$WUInstallStarted = Get-WinEvent -LogName System |
Where-Object ProviderName -eq "Microsoft-Windows-WindowsUpdateClient" |
Where-Object { $_.Id -eq "43" -and $_.Message -like "*Started* Update for Windows*" }
$InstallTime = '{0:HH:mm:ss on dd MMMM yyyy}' -f $WUInstallStarted.TimeCreated
$Configcontent = Get-Content -Path "$($PSADTKPath)\AppDeployToolkit\AppDeployToolkitConfig-Orig.xml"
# Change Banner image to 'Restart Required'
$NewConfigcontent = $Configcontent -replace "<Banner_Filename>MyCompany_software_distribution.png</Banner_Filename>","<Banner_Filename>MyCompany_restart_required.png</Banner_Filename>"
# Change output message
$NewConfigcontent = $NewConfigcontent -replace "<RestartPrompt_Message>In order for the installation to complete, you must restart your computer.</RestartPrompt_Message>","<RestartPrompt_Message>This months Windows Updates installed onto your machine at $($InstallTime). In order for this complete, you must restart your computer.</RestartPrompt_Message>"
$NewConfigcontent | Set-Content -Path "$($PSADTKPath)\AppDeployToolkit\AppDeployToolkitConfig.xml" -Force
Then if the detection script determines the criteria have been met, the remediation script is triggered
The script is quite simple, I set the Execution Policy so the script can successfully run, I set the $installTitle
to override the default window title, then set the $Deadline
, $CountdownSeconds
and $CountdownNoHideSeconds
(again) to override the defaults, finally (and this is where it fails) I run the Show-InstallationRestartPrompt
function (launched via ServiceUi.exe in the System context so the prompt āshouldā appear in the User context):
# dot source load the PSADTK code
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
. "$($PSADTKPath)\AppDeployToolkit\AppDeployToolkitMain.ps1"
# Set the Window Title - This overrides what is preset in the PSADTK
$installTitle = "Laptop restart required"
# Set the deadline for the restart (in hours)
[Int32]$Deadline = 8
#Convert Deadline to seconds plus 5 seconds (This gets wiped when the App Deploy Toolkit is loaded so can not be set earlier)
[int32]$CountdownSeconds = ((New-TimeSpan -Hours $Deadline).TotalSeconds + 5)
#Remove the ability to minimise the Warning message for the last x seconds (This gets wiped when the App Deploy Toolkit is loaded so can not be set earlier)
[int32]$CountdownNoHideSeconds = 600
# Show-InstallationRestartPrompt -CountdownSeconds $($CountdownSeconds) -CountdownNoHideSeconds $($CountdownNoHideSeconds)
& "$($PSADTKPath)\ServiceUI.exe" -process:explorer.exe C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe " -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command Show-InstallationRestartPrompt -CountdownSeconds $($CountdownSeconds) -CountdownNoHideSeconds $($CountdownNoHideSeconds) -NoSilentRestart $false"
When I say fails, if I try this run under the system context (psexec -i -s powershell.exe
) the command:
& "$($PSADTKPath)\ServiceUI.exe" -process:explorer.exe C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe " -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command Show-InstallationRestartPrompt -CountdownSeconds $($CountdownSeconds) -CountdownNoHideSeconds $($CountdownNoHideSeconds) -NoSilentRestart $false"
Will briefly show a new powershell command window (which immediately closes) and outputs the following to the existing PowerShell window on screen:
=======================
Matched Processes
=======================
Process Found: [explorer.exe] ID [9732] SESSION [1]
=======================
Logon Lookup
=======================
[winlogon.exe] Session: [1] PID [832] [Target Session [1] = Match]
=======================
Launch Process
=======================
Program to launch : [C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe]
Command line : [C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowsStyle Hidden -ExecutionPolicy Bypass -Command Show-InstallationRestartPrompt -CountdownSeconds 28805 -CountdownNoHideSeconds 120 -NoSilentRestart False]
Process launching with PID [14208]
Process exit code [1]
=======================
Exiting with [1]
=======================
and the AppDeployToolkit Log has to following content:
<![LOG[[Initialization] :: *******************************************************************************]LOG]!><time="12:57:57.84660" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: *******************************************************************************]LOG]!><time="12:57:57.84660" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: [PS_AppDeployToolkitMain_3.9.2_EN_01] setup started.]LOG]!><time="12:57:57.89360" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Script [C:\ProgramData\MyCompany\PSADTK\AppDeployToolkit\AppDeployToolkitMain.ps1] invoked directly]LOG]!><time="12:57:57.98760" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Script [C:\ProgramData\MyCompany\PSADTK\AppDeployToolkit\AppDeployToolkitExtensions.ps1] dot-source invoked by [C:\ProgramData\MyCompany\PSADTK\AppDeployToolkit\AppDeployToolkitMain.ps1]]LOG]!><time="12:57:58.01860" date="04-19-2023" component="PSAppDeployToolkitExt" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitExtensions.ps1">
<![LOG[[Initialization] :: [App Deploy Toolkit Main] script version is [3.9.2]]LOG]!><time="12:57:58.01860" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: [App Deploy Toolkit Extensions] version is [3.9.2]]LOG]!><time="12:57:58.03460" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Computer Name is [MYPC-0472]]LOG]!><time="12:57:58.03460" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Current User is [NT AUTHORITY\SYSTEM]]LOG]!><time="12:57:58.03460" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: OS Version is [Microsoft Windows 10 Enterprise 64-bit 10.0.19045.2728]]LOG]!><time="12:57:58.04960" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: OS Type is [Workstation]]LOG]!><time="12:57:58.04960" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Current Culture is [en-GB], language is [EN] and UI language is [EN]]LOG]!><time="12:57:58.04960" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Hardware Platform is [Physical]]LOG]!><time="12:57:58.11260" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: PowerShell Host is [ConsoleHost] with version [5.1.19041.2673]]LOG]!><time="12:57:58.12760" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: PowerShell Version is [5.1.19041.2673 x64]]LOG]!><time="12:57:58.12760" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: PowerShell CLR (.NET) version is [4.0.30319.42000]]LOG]!><time="12:57:58.14360" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: *******************************************************************************]LOG]!><time="12:57:58.14360" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Display session information for all logged on users:
NTAccount : MYDOMAIN\AScott15
SID : S-1-12-1-59410848-12850199999-3033817771-9999999999
UserName : AScott15
DomainName : MYDOMAIN
SessionId : 1
SessionName : Console
ConnectState : Active
IsCurrentSession : True
IsConsoleSession : True
IsActiveUserSession : True
IsUserSession : True
IsRdpSession : False
IsLocalAdmin : False
LogonTime : 19/04/2023 07:36:02
IdleTime : 00:00:00
DisconnectTime :
ClientName :
ClientProtocolType :
ClientDirectory :
ClientBuildNumber : 0
]LOG]!><time="12:57:59.95560" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The following users are logged on to the system: [MYDOMAIN\AScott15].]LOG]!><time="12:57:59.95560" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Current process is running with user account [NT AUTHORITY\SYSTEM] under logged in user session for [MYDOMAIN\AScott15].]LOG]!><time="12:57:59.97160" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The following user is the console user [MYDOMAIN\AScott15] (user with control of physical monitor, keyboard, and mouse).]LOG]!><time="12:57:59.98660" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The active logged on user is [MYDOMAIN\AScott15].]LOG]!><time="12:57:59.98660" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The active logged on user [MYDOMAIN\AScott15] has a primary UI language of [EN].]LOG]!><time="12:57:59.98660" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The following UI messages were imported from the config XML file: [UI_Messages_EN].]LOG]!><time="12:58:00.00260" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The active logged on user [MYDOMAIN\AScott15] has a DPI scale factor of [150] with DPI pixels [144].]LOG]!><time="12:58:00.01760" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Unable to load COM Object [Microsoft.SMS.TSEnvironment]. Therefore, script is not currently running from a SCCM Task Sequence.]LOG]!><time="12:58:00.01760" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [Schedule] exists.]LOG]!><time="12:58:00.29960" date="04-19-2023" component="Test-ServiceExists" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Getting the service [Schedule] startup mode.]LOG]!><time="12:58:00.31460" date="04-19-2023" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [Schedule] startup mode is set to [Automatic].]LOG]!><time="12:58:00.50260" date="04-19-2023" component="Get-ServiceStartMode" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Getting the service object for service [Schedule].]LOG]!><time="12:58:00.56460" date="04-19-2023" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Service [Schedule] with display name [Task Scheduler] has a status of [Running].]LOG]!><time="12:58:00.58060" date="04-19-2023" component="Start-ServiceAndDependencies" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: The task scheduler service is in a healthy state: True.]LOG]!><time="12:58:00.59560" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Session 0 detected, process running in user interactive mode, user(s) logged in.]LOG]!><time="12:58:00.59560" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
<![LOG[[Initialization] :: Deployment type is [Installation].]LOG]!><time="12:58:00.61160" date="04-19-2023" component="PSAppDeployToolkit" context="NT AUTHORITY\SYSTEM" type="1" thread="10872" file="AppDeployToolkitMain.ps1">
I have tried the command with -IgnoreExitCodes
appended (as per this suggestion pre-installation-execution-failed-with-exit-code-1) but still no joy
FYI: If I run this in the user context (after I have dot source loaded the AppDeployToolkitMain.ps1 script) e.g.
Show-InstallationRestartPrompt -CountdownSeconds $($CountdownSeconds) -CountdownNoHideSeconds $($CountdownNoHideSeconds)
The restart prompt successfully displays with the 8 hour countdown and works as expected
If anyone has any observations (especially about glaringly obvious errors in my code ), or suggestions how I might get this to work Iād be eternally grateful
N.B. One nice to have for PSADT would be to be able to include lines breaks (new lines) within in the xml elements in the AppDeployToolkitConfig.xml, so for example the Restart Prompt could be a little more customisable - I have tried using /n
or `n
or ``n
but sadly these donāt work.