Last active
March 13, 2018 14:14
-
-
Save calvinbui/6a69273f17b92013e0cf98963b2cc261 to your computer and use it in GitHub Desktop.
Windows Powershell Profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#—————————————————————————— | |
# PowerShell console profile | |
# Calvin Bui | |
# Put at C:\Users\Calvin\Documents\WindowsPowerShell\profile.ps1 | |
# Then run as admin: Set-ExecutionPolicy -ExecutionPolicy Unrestricted | |
# 7/5/17 - Added function to turn off screen (Turn-Off-Display) | |
#—————————————————————————— | |
#Aliases | |
Set-Alias -Name sudo -Value Start-ElevatedPowerShell | out-null | |
Set-Alias -Name Turn-Off-Display -Value Switch-DisplayOff | |
Function Start-ElevatedPowerShell | |
{ | |
Start-Process PowerShell -Verb Runas | |
} | |
# Source: http://www.powershellmagazine.com/2013/07/18/pstip-how-to-switch-off-display-with-powershell/ | |
# Turn display off by calling WindowsAPI. | |
# SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF) | |
# HWND_BROADCAST 0xffff | |
# WM_SYSCOMMAND 0x0112 | |
# SC_MONITORPOWER 0xf170 | |
# POWER_OFF 0x0002 | |
Add-Type -TypeDefinition ' | |
using System; | |
using System.Runtime.InteropServices; | |
namespace Utilities { | |
public static class Display | |
{ | |
[DllImport("user32.dll", CharSet = CharSet.Auto)] | |
private static extern IntPtr SendMessage( | |
IntPtr hWnd, | |
UInt32 Msg, | |
IntPtr wParam, | |
IntPtr lParam | |
); | |
public static void PowerOff () | |
{ | |
SendMessage( | |
(IntPtr)0xffff, // HWND_BROADCAST | |
0x0112, // WM_SYSCOMMAND | |
(IntPtr)0xf170, // SC_MONITORPOWER | |
(IntPtr)0x0002 // POWER_OFF | |
); | |
} | |
} | |
} | |
' | |
function Switch-DisplayOff | |
{ | |
[Utilities.Display]::PowerOff() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment