title: How do I log off all currently logged on users?
body: <p>I would like to create a GPO that includes a scheduled task, that should be run once every day. The scheduled task should get a list of all users currently logged on a specific workstation and log them off (just lock Windows would be prefered, but a regular log off seems easier to make)</p>
  
  <p>First I tried to execute the following with the scheduled task:
  "shutdown.exe /f /l" to log off users. But the command was being executed by the SYSTEM user, so all regular users was not being logged off. </p>
  
  <p>2nd idea was then to create a Powershell Script and place on each workstation. The script should be able to extract all currently logged on users on the workstation and log off / lock screen for all users. </p>
  
  <pre><code>$Sessions = quser
  
  # Parse the session IDs from the output
  $SessionIds = ($Sessions -split ' +')[3]
  $SessionIds
  
  # Loop through each session ID and pass each to the logoff command
  ForEach-Object ($SessionId in $SessionIds){
      logoff $SessionId
      } 
  </code></pre>