If you’d like to lock the current workstation from within PowerShell, you can take advantage of the fact that PowerShell can run executables. Here is a quick function that uses rundll32.exe to call an internal Windows function that locks the workstation:

function Lock-Workstation
  rundll32.exe user32.dll,LockWorkStation

Twitter This Tip! ReTweet this Tip!