Variable "$CurrentLoggedOnUserSession.IsUserSession" is NULL with Intune

We have a problem with the PSAppDeploy variable $CurrentLoggedOnUserSession.IsUserSession. We use this with the config manager to find out if a user is logged in. If no user is logged in or the PC is locked the variable is $false.
If you run the app with intune (same script) the value of the variable is always NULL. So the application exits without starting the installation.

Example:




if ($CurrentLoggedOnUserSession.IsUserSession) 
				{
				Write-Log -Message "User is currently logged on, starting installation..."
				Show-InstallationWelcome -CloseApps 'cidaemon' -BlockExecution -ForceCloseAppsCountdown 120 -AllowDefer -DeferTimes 3 -PersistPrompt}

Is this a known bug?

Not known yet as per Issues · PSAppDeployToolkit/PSAppDeployToolkit · GitHub

At work we don’t have InTune yet so I cannot try to reproduce.

Tip: When posting code, please format it with </> to make it more readable. It makes people more likely to try/read it.

EDIT: you now have company: PSADT and Windows Active Hours

I’m going to added the if ($CurrentLoggedOnUserSession.IsUserSession) to the App Deploy script as provided by @Klaus . Since I want the user to be confirmed as logged off, I will add it as:
if (!$CurrentLoggedOnUserSession.IsUserSession)

This is my first time editing the script. How can I write an exit code for InTune (SCCM code I guess would be the same) to let InTune know to try again at the next synch cycle? So, if the user is logged in, don’t install but try again.

I don’t know which errorcode/exitcode will tell InTune to try again at the next sync cycle but this is how you exit PSADT with a specific exitcode:

Exit-Script -Exitcode 10

Good luck

So, I decided to use in the Pre-installation section:
if (Get-Process CiscoJabber -ErrorAction SilentlyContinue) {
Exit-Script -ExitCode 69001
}
If that application is running, the script exits. It worked as the application deployment didn’t install and I see in the log created by PSADT the exit code. An error returned to InTune: 0x80070D89. So far, I cannot find anything on that error.

I will also try with CurrentLoggedOnUserSession… for the benefit of @Klaus

some programs cannot handle error codes above 65635.
I think InTune is one of them.

If you paste 69,001 in calculator, look at the HEX output: 10D89