Change Your Computer's State Using PowerShell

Lock a Computer

You can lock a computer by calling the LockWorkStation ( ) method in user32.dll.

Example

PS C:\ > rundll32.exe user32.dll, LockWorkStation

CMD

Shutdown a Computer

To shutdown a local computer, use Stop-Computer Cmdlet.

Example

PS C:\> Stop-Computer

CMD

Shutdown a Remote Computer

To shutdown a remote computer, use -ComputerName parameter and provide the remote computer name.

Example

PS C:\ > Stop-Computer -ComputerName “Your Remote Computer Name Here”

Restart a Computer

You can Restart a computer using Restart-Computer Cmdlet.

Example

PS C:\> Restart-Computer

CMD

Restart a Remote Computer

You can restart a remote computer by providing the remote computer name using -ComputerName parameter .

Example

PS C:\ Restart-Computer -ComputerName “Your Remote Computer Name Here”.

Log off the Current Session

Use shutdown.exe to log off the current session.

Example

PS C:\> shutdown.exe -l

CMD

Note

Option: You can just use shutdown.exe to log off the current session.