Unable to get Show-InstallationRestartPrompt function to work with ServiceUI.exe

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 :joy:), 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.

1 Like

Hi AScott15,

I canā€™t help much since I do not have access to InTune yet at work.
Have you looked at the 3.9.3 beta?

1 Like

Hi, Thanks for the reply

Sorry my ramblings may not have been entirely clear - The intention will eventually be to run (deploy) it from Intune, but so far Iā€™m failing at the first hurdle when run from the System Account (using psexec):

PSADT is correctly detecting it is running from the System account (from the log):

Iā€™m just not sure why this wonā€™t work currently, by the time I can see the PID (thread="10972" in the log), the thread has closed.

Thanks for the heads up regarding the v3.9.3 beta, No I had not tried it so maybe itā€™s worth a punt.
Iā€™ll be back to report my findings in due courseā€¦

Thanks Adrian

1 Like

Where i can find 3.9.3 beta? If I click on the link, i donā€™t see beta version

If you use a tablet or a small window you will not see the green button.

good, If I unzip the file, i found the toolkit folder, but where is the beta folder?

no such thing as a ā€œBetaā€ folder.
If you compare 3.9.2 and what you just DLā€™d, some are different.
Since itā€™s not ā€œReleasedā€, I call it Beta.

I have since tried my code with the released version of v3.9.3 but it still doesnā€™t work.
So after specifically seeing : Deployment type is [Installation] within the last line of the original log (above in my first post):

<![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">

it made me realise PSADT is probably trying to perform an Installation (but not finding a suitable install command), So it made me consider trying a different tack, rather than dot sourcing the AppDeployToolkitMain.ps1 script, I will try putting my Show-InstallationRestartPrompt command

Show-InstallationRestartPrompt -CountdownSeconds $($CountdownSeconds) -CountdownNoHideSeconds $($CountdownNoHideSeconds) -NoSilentRestart $false

within the Post Installation steps of Deploy-Application.ps1
I guess I may still need to have a ā€˜dummy install commandā€™ e.g. ā€œdir C:\tempā€ within the Install section?
Letā€™s see if this works, Iā€™ll report back when I have tried

2 Likes

Hello Adrian,

have you find a solution?

Thanks

Iā€™m still working on this when I get time - I think I have concluded that running it as . sourced doesnā€™t seem to work for some reason, so I have reverted to using a customised deploy-application.ps1 script.
I couldnā€™t get this to work either, but then realised this was my mistake - I had the Show-InstallationRestartPrompt command inside the If statement that checks the $useDefaultMsi was not used:

        If (-not $useDefaultMsi) {
            Show-InstallationRestartPrompt -CountdownSeconds $($CountdownSeconds) -CountdownNoHideSeconds $($CountdownNoHideSeconds) -NoSilentRestart $false
        }

Sadly I ran out of time before my test machine updated and restarted this month, but in preparation I have commented out the If statement so I am ready to retest this after 11th July (i.e. July 2023 Patch Tuesday), it is now:

        # If (-not $useDefaultMsi) {
            Show-InstallationRestartPrompt -CountdownSeconds $($CountdownSeconds) -CountdownNoHideSeconds $($CountdownNoHideSeconds) -NoSilentRestart $false
        # }

:crossed_fingers:

2 Likes

Well a (not so quick) update on this - I have it working (and so far with great success) :tada:

As a reminder, my aim was to provide our users with a restart prompt (ā€œNagā€ :wink:) to get them to restart their machines after the install of either Windows Updates or System Updates or after their machine had been running for a number of days without a restart. This was mainly to fix update compliance and potential reliability issues.
N.B. I am using PSADT v3.9.3 for this

Unfortunately I had to go back to the drawing board somewhat with the design of this, as with my original plan I couldnā€™t get the Show-InstallationRestart to work reliably when when run from a dot source loaded AppDeployToolkitMain.ps1:

# dot source load the PSADTK code
    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
    . "$($PSADTKPath)\AppDeployToolkit\AppDeployToolkitMain.ps1"

It was to be launched via ServiceUI.exe, so the user sees the messaging interactively (the following line was triggered during an Intune Proactive Remediation, remediation script)

& "$($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"

So my new solution involved creating a ā€œtemplatedā€ Deploy-Application.ps1 (cleverly named Deploy-Application(Template).ps1) and a templated AppDeployToolkitConfig.xml (named AppDeployToolkitConfig-Orig.xml), then repackaging the Toolkit and deploying to each users machine. This gives a baseline toolkit we can then manipulate to create bespoke messaging based on the state of the users device.
FYI: In my Deploy-Application(Template).ps1:
I have placed ā€˜variablesā€™ (text to be replaced) in the ## Variables: Application section (from approx line 110), commented out all the Show-Installation* lines and I have strategically placed a number of # <step>TaskVariable lines, this way I could (via PowerShell) do a search and replace to set the commands I wish the PSADT to execute when run.
In my AppDeployToolkitConfig-Orig.xml:
I have my usual customisations (Branding, Logfolder and turn off Balloon Notifications)

I have a Proactive Remediation 'SEC-RestartRequired` which consists of two scripts -
Detect-RestartRequired.ps1 & Remediate-RestartRequired.ps1

Detect-RestartRequired.ps1 Includes a tweaked copy of the Get-PendingReboot function from PSADT - just to make it easier to capture if a Windows Update or System Update reboot is still pending, as well as the logic to read the Deploy-Application(Template).ps1 search and replace and then write a new PSADT Deploy-Application.ps1 and read the AppDeployToolkitConfig-Orig.xml search and replace and then write a new PSADT AppDeployToolkitConfig.xml file - In all this has been achieved in 464 lines of PowerShell
The new Deploy-Application.ps1 file is executed by the remediation Script:

Remediate-RestartRequired.ps1
Basically this only runs the Deploy-Application.ps1 if the PRā€™s Detect script determines if a restart is required, this uses ServiceUI.exe to bring the messages from the SYSTEM context to the logged on Users context
N.B. I have created an $OrgName variable so the code can be modified on a per organisation basis

<#
############################################
#  Remediate-RestartRequired.ps1  #
############################################

Detect if machine is pending a restart.

Used in Proactive Remediation "SEC-RestartRequired"

This script must be run in the SYSTEM context

Adrian Scott
1st August 2023

#########################################################################################
#>

#region Config
$AppName = "Remediate-RestartRequired"
$OrgName = "My-Company"
$LogPath = "$($env:ProgramData)\Microsoft\IntuneManagementExtension\logs"
$LogFile = "$($LogPath)\$($OrgName)-$($AppName).log"
$PSADTKPath = "C:\ProgramData\$($OrgName)\PSADTK" #Default Path to PowerShell App Deploy Toolkit
#endregion

#region Main process
if (!(Test-Path $LogPath)) {mkdir $LogPath -Force | Out-Null}
Start-Transcript -Path $LogFile -Force

try
{
    Write-Output "Machine now prompting user to restart"
    # Set the Window Title - This overrides what is preset in the PSADTK
    $installTitle = "$($OrgName) Laptop restart required"

    & "$($PSADTKPath)\ServiceUI.exe" -process:explorer.exe C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe " -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File $($PSADTKPath)\Deploy-Application.ps1"
    # Exit-Script -ExitCode 1618
} catch {
    $errorVar = $_.Exception.Message
} finally {
    if ($errorVar) {
        Write-Output "Something went wrong"
        Stop-Transcript | Out-Null
        Throw $errorVar
    } else {
        # Write-Output "No errors detected"
        Stop-Transcript | Out-Null
    }    
}
#endregion Main process

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.