Exception calling "Add" with "1" Argument(s): "value cannot be null"

I am trying to louch deferral option , here is the facing error . >

Position message : appdeploymentextenstions.ps1

Create new trigger

    $dailyTrigger = New-Object Microsoft.Win32.TaskScheduler.TimeTrigger # enable trigger
    $dailyTrigger.StartBoundary = [datetime]::Now + [timespan]::FromSeconds($timeTrigger)
    $taskDef.Triggers.Add($dailyTrigger)

Here is the deffer logic .

Stop the script (user chose to defer)

			ElseIf (($promptResult -eq 'Defer') -and ([math]::floor($closeAppsCountdownGlobal) -gt 1020)) {
					Write-Log -Message 'Installation deferred by the user.' -Source ${CmdletName}
					$BlockExecution = $false

					Set-DeferHistory -DeferTimesRemaining $DeferTimes -DeferDeadline $deferDeadlineUniversal

					#  Restore minimized windows
					$null = $shellApp.UndoMinimizeAll()
					WRite-Log -Message "deferred at $closeAppsCountdownGlobal" -Source ${CmdletName}
					DeferTask -scriptLocation "$scriptDirectory\Deploy-Application.exe" -scriptArguments "-DeferredTask 'True'" -timeTrigger ([math]::floor($closeAppsCountdownGlobal-900))
					Exit-Script -ExitCode $configInstallationDeferExitCode
			}
			ElseIf (($promptResult -eq 'Defer') -and ([math]::floor($closeAppsCountdownGlobal) -le 1020)) {
					Write-Log -Message 'Not enough time left to defer' -Source ${CmdletName}
					[string]$promptResult = Show-WelcomePrompt -ProcessDescriptions $runningProcessDescriptions -CloseAppsCountdown $closeAppsCountdownGlobal -ForceCloseAppsCountdown $forceCloseAppsCountdown -ForceCountdown $forceCountdown -PersistPrompt $PersistPrompt -MinimizeWindows $MinimizeWindows -CustomText:$CustomText -TopMost $TopMost
			}

please reply As early as possible.

$dailyTrigger is empty when $taskDef.Triggers.Add is called. Probably due to Microsoft.Win32.TaskScheduler not being loaded.

but this working on windows 10 env without fail.

i am facing this issue with only windows 7 32 / 64 bit

Windows 7 comes with powershell 2.0 not 5.1 like windows 10

But I do not think this is the main problem here. The class TaskScheduler does not seem to exist in the namespace Microsoft.Win32 based on Microsoft .Net Framework documentation:

If you’re using a library like GitHub - dahall/TaskScheduler: Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
You need to include it with the package and import it before using it.

Thank you @luki1412

when i discussed with my team member. i found in this script there is two files working with collaboration.
1- AppDeploymentToolkitMain.ps1
2- AppDeploymentTookkitExtensions.ps1

below are the logic details.

1- AppDeploymentToolkitMain.ps1

Stop the script (user chose to defer)

			ElseIf (($promptResult -eq 'Defer') -and ([math]::floor($closeAppsCountdownGlobal) -gt 1020)) {
					Write-Log -Message 'Installation deferred by the user.' -Source ${CmdletName}
					$BlockExecution = $false

					Set-DeferHistory -DeferTimesRemaining $DeferTimes -DeferDeadline $deferDeadlineUniversal

					#  Restore minimized windows
					$null = $shellApp.UndoMinimizeAll()
					WRite-Log -Message "deferred at $closeAppsCountdownGlobal" -Source ${CmdletName}
					DeferTask -scriptLocation "$scriptDirectory\Deploy-Application.exe" -scriptArguments "-DeferredTask 'True'" -timeTrigger ([math]::floor($closeAppsCountdownGlobal-900))
					Exit-Script -ExitCode $configInstallationDeferExitCode
			}
			ElseIf (($promptResult -eq 'Defer') -and ([math]::floor($closeAppsCountdownGlobal) -le 1020)) {
					Write-Log -Message 'Not enough time left to defer' -Source ${CmdletName}
					[string]$promptResult = Show-WelcomePrompt -ProcessDescriptions $runningProcessDescriptions -CloseAppsCountdown $closeAppsCountdownGlobal -ForceCloseAppsCountdown $forceCloseAppsCountdown -ForceCountdown $forceCountdown -PersistPrompt $PersistPrompt -MinimizeWindows $MinimizeWindows -CustomText:$CustomText -TopMost $TopMost
			}

2- AppDeploymentTookkitExtensions.ps1

Create new trigger

    $dailyTrigger = New-Object Microsoft.Win32.TaskScheduler.TimeTrigger # enable trigger
    $dailyTrigger.StartBoundary = [datetime]::Now + [timespan]::FromSeconds($timeTrigger)
    $taskDef.Triggers.Add($dailyTrigger)

As my team member says, ([math]::floor($closeAppsCountdownGlobal-900)) this command not pulled value …OR the math command not supported to windows 7 OR less powershell version.

[Math]::Floor is supported on Powershell 2.

The error message you posted in the first post literally says the problem is $dailyTrigger

1 Like