Instructions for use:
Used on PSADT version: 3.9.3.
Folder Structure:
A folder called “SupportFiles” is required in the PSADT root folder and should contain the files: “PsExec64.exe” & “ServiceUI_x64.exe”.
Command Lines:
To run via SCCM or Manual Install with Invoke function use command line: “Deploy-Application.exe Install -Invoke” or “Deploy-Application.exe Uninstall -Invoke”.
Otherwise, to run via SCCM or Manual Install without Invoke function use command line: “Deploy-Application.exe Install” or “Deploy-Application.exe Uninstall”.
SCCM Deployment Settings:
Installation behaviour: Install for System.
Login requirement: Whether or not a user is logged on.
Installation program visibility: hidden
Untick - "Allow users to view and interact with the program installation”.
Functionality:
It integrates the Invoke functionality into “Deploy-Application.ps1” script using script blocks located in “AppDeployToolkitExtensions.ps1”.
Invoke is used to determine if a user is logged in or not and run the appropriate type of install. No user logged in: (non-interactive)Silent install / User logged in: (interactive)Full UI.
The invoke works by first running “Deploy-Application.ps1” with the -Invoke switch, this means it goes into the “Invoke_Type” script block where it determines if a user is logged on or not.
“Deploy-Application.ps1” is then run again (in parallel) without the -Invoke switch using the method determined in the “Invoke_Type” Script block. As -Invoke is not specified the script runs as normal.
This is a slightly simplified version of what we run in our environment.
@PaulH has designed a more in-depth version that we run which detects RDP and Disconnected RDP sessions. This is to make sure it runs interactively on these occasions.
This allows us to have one deployment type that we can use for both builds and for existing clients, as it can run whether or not a user is logged on!
I understand that this will be helpful for Intune deployments, as a PSADT will run interactively when a user is logged on.
#Add to Param in Deploy-Application.ps1:
## CUSTOM PARAMETERS
[Parameter(Mandatory = $false)]
[switch]$Invoke
#Add after the .Source is done in Deploy-Application.ps1:
##*===============================================
## CUSTOM: If $Invoke, Invoke Run through.
If ($Invoke) { & $Invoke_Type }
##*===============================================
#Add Script Blocks below to AppDeployToolkitExtensions.ps1:
## Determine whether a user is logged on or not, then invoke the appropriate script block
$Invoke_Type = {
## Settings/Variables:
$configShowBalloonNotifications = $false <# Override the setting in the XML, turning balloon notifications OFF #>
$writelogSource = 'Invoke-Deploy-Applcation' <# Write-Log Component name #>
$AllowRebootPassThru = $true <# Allow the script to exit with a reboot code, if one has been passed from Deploy-Application.ps1 #>
Write-Log 'PSADT is running with the "-Invoke" switch.' -Source $writelogSource -Severity 2
## Invoke the script block.
If ($usersLoggedOn)
{
Write-Log 'A user is logged on to the Console session. PSADT will run interactively with ServiceUI.' -Source $writelogSource -Severity 2
& $Invoke_ServiceUI_PsExec
} else {
Write-Log 'No one is logged on. PSADT will run non-interactive by default.' -Source $writelogSource -Severity 2
& $Invoke_DeployApplication
}
}
## When no users are logged on, launch 'Deploy-Application.exe'. PSADT will run non-interactive.
$Invoke_DeployApplication = {
[psobject]$ExecuteProcessResult = Execute-Process -Path "$scriptParentPath\Deploy-Application.exe" -Parameters $DeploymentType -PassThru
Write-Log -Message "The Invoke scriptblock completed with exit code [$($ExecuteProcessResult.ExitCode)]" -Source $writelogSource -Severity 2
## Exit the script
[Int32]$mainExitCode = $ExecuteProcessResult.ExitCode
Exit-Script -ExitCode $mainExitCode
}
## When a user is logged on, launch PSADT 'interactive' via PsExec and ServiceUI.
$Invoke_ServiceUI_PsExec = {
[string]$PsExecParameters = "-accepteula -s -w `"$dirSupportFiles`" `"$dirSupportFiles\ServiceUI_x64.exe`" -process:explorer.exe ..\Deploy-Application.exe $DeploymentType"
[psobject]$ExecuteProcessResult = Execute-Process -Path "$dirSupportFiles\PsExec64.exe" -Parameters $PsExecParameters -PassThru
Write-Log -Message "The Invoke scriptblock with PsExec completed with exit code [$($ExecuteProcessResult.ExitCode)]" -Source $writelogSource -Severity 2
## Exit the script
[Int32]$mainExitCode = $ExecuteProcessResult.ExitCode
Exit-Script -ExitCode $mainExitCode
}