Function Lock-Workstation locally and remotely
You can do everything with PowerShell, as well as locking your workstation with one simple function call.
Just call the
LockWorkstation() function in user32.dll and that’s it! The fine thing is, it works on a local and a remote session.