Start-Sleep 1 C:\Windows\System32\net.exe user Marek /active:no $session_id = ((C:\Windows\System32\quser.exe | Where-Object {$_ -match 'Marek' }) -split ' +')[2] If ($session_id) { logoff $session_id Start-Sleep 1 shutdown /s /f /t 0 }