Tip of the day: Aprils Fools Day pranks with Powershell Part 3
Apply these pranks to your colleagues’ computers. They will be surprised and will have a good laugh.
Note: These pranks are harmless and will not cause any damage to the computer. They are just for fun.
Note: If you have any other ideas for pranks, please share them in the comments.
Random Caps Lock Toggling:
1
2
3
4
5
Add-Type -AssemblyName System.Windows.Forms
For ($i = 0; $i -lt 100; $i++) {
[System.Windows.Forms.SendKeys]::SendWait("{CAPSLOCK}")
Start-Sleep -Milliseconds 500
}
Tip: You can replace
{CAPSLOCK}
with{NUMLOCK}
or{SCROLLLOCK}
to toggle those keys instead.
Tip: Save as a script and run it in the background to annoy your colleagues.
Change Their Prompt to a Funny Message:
1
2
3
function prompt { "🤡 You have been hacked: PS> " }
Tip: Add this function to your PowerShell profile to make it permanent.
Fake typing Effect:
1
2
3
4
5
6
$text = "You shouldn’t have left your PC unlocked... 😏"
foreach ($c in $text.ToCharArray()) {
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait($c)
Start-Sleep -Milliseconds 300
}
Tip: Save as a script and run it in the background to annoy your colleagues. On execution it will start typing the message on the active window.
Shift the screen slightly to make them think the display is off-center:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Screen]::AllScreens | ForEach-Object {
rundll32.exe user32.dll,SwapMouseButton
}
# Switch back
# Add-Type @"
# using System;
# using System.Runtime.InteropServices;
# public class MouseHelper
# {
# [DllImport("user32.dll")]
# public static extern bool SwapMouseButton(bool fSwap);
# }
# "@
# [MouseHelper]::SwapMouseButton($false)
Tip: this one very annoying, so use it wisely.
Open random message box with a funny message:
1
2
3
for ($i = 0; $i -lt 5; $i++) {
[System.Windows.Forms.MessageBox]::Show("April Fools! 😜")
}
Invert screen colors temporarily (Magnifier toggle)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Start-Process "magnify.exe"
Start-Sleep -Seconds 1
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Keyboard {
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
}
"@
# Ctrl + Alt + I keys pressed (invert colors)
[Keyboard]::keybd_event(0x11,0,0,0) # Ctrl down
[Keyboard]::keybd_event(0x12,0,0,0) # Alt down
[Keyboard]::keybd_event(0x49,0,0,0) # I down
[Keyboard]::keybd_event(0x49,0,2,0) # I up
[Keyboard]::keybd_event(0x12,0,2,0) # Alt up
[Keyboard]::keybd_event(0x11,0,2,0) # Ctrl up
Start-Sleep -Seconds 30
# Invert back by sending keys again
[Keyboard]::keybd_event(0x11,0,0,0)
[Keyboard]::keybd_event(0x12,0,0,0)
[Keyboard]::keybd_event(0x49,0,0,0)
[Keyboard]::keybd_event(0x49,0,2,0)
[Keyboard]::keybd_event(0x12,0,2,0)
[Keyboard]::keybd_event(0x11,0,2,0)
# Close magnifier
<!-- Stop-Process -Name magnify -Force -->
Ultimate PowerShell Prank Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class MouseHelper {
[DllImport("user32.dll")]
public static extern bool SwapMouseButton(bool fSwap);
}
public class CDTray {
[DllImport("winmm.dll")]
public static extern int mciSendString(string command, string returnValue, int returnLength, int winHandle);
}
"@
Add-Type -AssemblyName System.Windows.Forms
function Swap-MouseButtons {
[MouseHelper]::SwapMouseButton($true)
[System.Windows.Forms.MessageBox]::Show("System Configuration: Mouse re-mapped successfully!","System")
Start-Sleep -Seconds 30
[MouseHelper]::SwapMouseButton($false)
}
function Invert-Screen {
Start-Process "magnify.exe"
Start-Sleep -Seconds 2
$VK_CTRL = 0x11; $VK_ALT = 0x12; $VK_I = 0x49
Add-Type @"
using System.Runtime.InteropServices;
public class Keyboard {
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
}
"@
function Send-Keys($vk1,$vk2,$vk3){
[Keyboard]::keybd_event($vk1,0,0,0)
[Keyboard]::keybd_event($vk2,0,0,0)
[Keyboard]::keybd_event($vk3,0,0,0)
[Keyboard]::keybd_event($vk3,0,2,0)
[Keyboard]::keybd_event($vk2,0,2,0)
[Keyboard]::keybd_event($vk1,0,2,0)
}
Send-Keys $VK_CTRL $VK_ALT $VK_I
Start-Sleep -Seconds 20
Send-Keys $VK_CTRL $VK_ALT $VK_I
Stop-Process -Name magnify -Force
}
function Rotate-Screen {
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Display {
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettings(ref DEVMODE devMode, int flags);
[DllImport("user32.dll")]
public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
public const int ENUM_CURRENT_SETTINGS = -1;
public const int CDS_UPDATEREGISTRY = 0x01;
[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE {
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public int dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string dmFormName;
public short dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
}
}
"@
$devmode = New-Object Display+DEVMODE
$devmode.dmSize = [System.Runtime.InteropServices.Marshal]::SizeOf($devmode)
[Display]::EnumDisplaySettings($null, [Display]::ENUM_CURRENT_SETTINGS, [ref]$devmode) | Out-Null
$devmode.dmDisplayOrientation = 1
[Display]::ChangeDisplaySettings([ref]$devmode, [Display]::CDS_UPDATEREGISTRY)
Start-Sleep -Seconds 20
$devmode.dmDisplayOrientation = 0
[Display]::ChangeDisplaySettings([ref]$devmode, [Display]::CDS_UPDATEREGISTRY)
}
function Random-Popups {
1..7 | ForEach-Object {
Start-Sleep -Seconds (Get-Random -Minimum 5 -Maximum 12)
[System.Windows.Forms.MessageBox]::Show("Critical system alert #$($_). Please restart immediately. Just kidding. 😜","Windows Security")
}
}
$pranks = @("Swap-MouseButtons","Invert-Screen","Rotate-Screen","Random-Popups")
# Launch them all in random order with pauses for maximum confusion
$pranks | Sort-Object {Get-Random} | ForEach-Object {
Start-Sleep -Seconds (Get-Random -Minimum 10 -Maximum 20)
Write-Host "Running prank: $_"
Invoke-Command -ScriptBlock (Get-Command $_).ScriptBlock
}
[System.Windows.Forms.MessageBox]::Show("All systems restored. Happy April Fools! 😁","Windows")
Tip: This is ultimate prank script, use it wisely.
If you missed the first part of the pranks, you can find them here >
Tip of the day - Powershell for April first. Tricks and pranks
Tip of the day - Powershell for April first. Tricks and pranks Part 2