Check if a user is logged-in with PowerShell

Patching machines is usually a constraint for the end user, mainly because of the reboot required at the end of the update…

A good workaround to update machines without disrupting the user is to apply the patch and then reboot when no user is logged on the machine.

Many possibilities exist to check whether a user is logged on a machine or not, one of them is to check if an “Explorer” process is running on the machine.

Here is a PowerShell script allowing to achieve this: