$cs.Sys_isUserLoggedOn
Description
Section titled “Description”Checks whether a user is currently logged on to the desktop/console session. Takes no parameters.
Syntax
Section titled “Syntax”$cs.Sys_isUserLoggedOn()
Parameters
Section titled “Parameters”None.
Return value
Section titled “Return value”Boolean. $true if a user is currently logged on, otherwise $false.
Example
Section titled “Example”Skip a disruptive forced restart when a user is currently logged on:
if ($cs.Sys_isUserLoggedOn()){ $cs.Job_WriteLog("A user is logged on, skipping forced restart")}Branch between running a step in the logged-on user’s context and a silent SYSTEM-only path:
if ($cs.Sys_isUserLoggedOn()){ $cs.Job_WriteLog("User is logged on, running configuration script in user context") Invoke-RunAsLoggedOnUser -command "powershell.exe" -arguments "-ExecutionPolicy Bypass -File `"$global:Packageroot\Configure-UserSettings.ps1`""}else{ $cs.Job_WriteLog("No user logged on, skipping user-context configuration")}