4.1.3 - How to skip all operations on reboot pending or wrong computername

With PSADT up to 3.10.2, I was able to skip all (install/uninstall/repair) actions on some conditions, e.g.

  • Pending Reboot detected (exit and pass back code 3010)
  • Computername out of scope (just skip and exit)

How can this be achieved with the latest 4.1.3 v4 module script?

Here's the example snippet of 3.10.2:


...
[CmdletBinding()]
Param (
    [switch]$AllowRebootPassThru = $true,
)
...

    ##*===============================================
    #endregion END VARIABLE DECLARATION
    ##*===============================================

	## Check for pending reboot
	write-log 'Check for penting restart...'
	if ((Get-PendingReboot).IsSystemRebootPending) {
		write-log '*** PENDING RESTART, skipping all operations...(Intune will re-check every 8h)'
		$mainExitCode=3010
	} # end of If ((Get-PendingReboot).IsSystemRebootPending)
	Else { 
	write-log '*** NO restart pending was detected, starting intended operation...'
	
	## Run on CH computers only
	if ($env:COMPUTERNAME -like "ch*") 
    {

    If ($deploymentType -ine 'Uninstall' -and $deploymentType -ine 'Repair') {
	#...
	} # End of If ($deploymentType -ine 'Uninstall' -and $deploymentType -ine 'Repair')
    ElseIf ($deploymentType -ieq 'Uninstall') {
	#...
    } # End of ElseIf ($deploymentType -ieq 'Uninstall')
    ElseIf ($deploymentType -ieq 'Repair') {
	#...
    } # End of ElseIf ($deploymentType -ieq 'Repair')

	} # end of if ($env:COMPUTERNAME -like "ch*") 
	} # end of If ((Get-PendingReboot).IsSystemRebootPending) Else

    ##*===============================================
    ##* MARK: END SCRIPT BODY
    ##*===============================================
...



You'd just put your conditional code somewhere around here so it occurs before & "$($adtSession.DeploymentType)-ADTDeployment" is called.

Thank you for the hint, I'll try.