How to detect logged on users in Task Sequences

It’s easy to deploy a package to workstations and reboot when no users are logged on. All you need to do is just set “Only when no user is logged on” on program properties. But SCCM TS don’t have such “luxury”, basically because Task Sequences are used for OS deployment, means no users or they already were kicked out.

One of TSes I use to upgrade drivers. Complexity of conditions (registry settings, file versions, type of devices, users are logged or not etc) makes it difficult to upgrade drives in “classical way”: create collections for for each of possible combinations, two-three programs and numerous adverts.  Instead I have just one deployment of single TS and able reuse my staging collections I use for patch management.

A simple WMI query helps to detect logged users:
SELECT * FROM Win32_LogonSession WHERE LogonType =2

And another one for device type:
SELECT * FROM Win32_OperatingSystem where ProductType = 1

ProductType is 1 for worstations, 2 for Domain Controllers, and 3 is for member servers.

This PowerShell script gives you all info about logged users if any
Get-WmiObject -Class Win32_LogonSession | ? {$_.LogonType -eq 2} | fl *

And this one for Operating System details
Get-WmiObject -Class Win32_OperatingSystem | fl *

Advertisements

About oleggap

IT Pro
This entry was posted in Uncategorized. Bookmark the permalink.