First from CMD, that is pretty easy:

rundll32.exe user32.dll, LockWorkStation

Now, with PowerShell, it is about the same, we call the user32.dll, just it is a little more work to get that to work right:

$script:nativeMethods = @();
function Register-NativeMethod([string]$dll, [string]$methodSignature)
    $script:nativeMethods += [PSCustomObject]@{ Dll = $dll; Signature = $methodSignature; }
function Add-NativeMethods()
    $nativeMethodsCode = $script:nativeMethods | foreach { "
        public static extern $($_.Signature);
    " }
    Add-Type @"
        using System;
        using System.Runtime.InteropServices;
        public static class NativeMethods {
Register-NativeMethod "user32.dll" "bool LockWorkStation()"

Credit for how to call DLLs from PowerShell goes to Danny.