I'm trying to get all users logged off at certain time. For that I wrote a one-liner
qwinsta | select-string -notMatch "services" | % {logoff ($_.toString() -split ' +')[2] -Force}
The one-liner works fine on it's own yet when I create a task that runs under SYSTEM scheduled for certain time of day and for Action I set "powershell.exe -noprofile -command "c:\scripts\logoff_users.ps1" " the task starts and it does nothing just sitting in Running state. Is there anything in the script that would cause it? What am I missing?