Skip to content

Instantly share code, notes, and snippets.

@amphineko
amphineko / lock-and-sleep.ps1
Created July 22, 2019 19:34
PowerShell script to lock workstation and turn off monitor
<#
This PowerShell script locks your current session, then immediately turns off your monitor.
You don't have to wait for or alter your screen timeout,
or use a sleep button set to turning off monitor that doesn't exist on your computer.
#>
$LockWorkStation = Add-Type -Name "Win32LockWorkStation" -PassThru -MemberDefinition @"
@jamesfreeman959
jamesfreeman959 / keepawake.ps1
Last active April 10, 2025 06:42
A very simple PowerShell script to keep a Windows PC awake and make lync think the user is active on the keyboard
# Useful references:
#
# https://superuser.com/questions/992511/emulate-a-keyboard-button-via-the-command-line
# https://ss64.com/vb/sendkeys.html
# https://social.technet.microsoft.com/Forums/windowsserver/en-US/96b339e2-e9da-4802-a66d-be619aeb21ac/execute-function-one-time-in-every-10-mins-in-windows-powershell?forum=winserverpowershell
# https://learn-powershell.net/2013/02/08/powershell-and-events-object-events/
#
# Future enhancements - use events rather than an infinite loop
$wsh = New-Object -ComObject WScript.Shell
while (1) {