Making Music (with PowerShell)
![I'd like to imagine what this sounds like in [System.Console]::Beep](/content/images/size/w2000/2024/06/PowerShell_Music.webp)
Did you know you can make music using PowerShell and the [System.Console]::Beep
command?
Well I didn't until I was looking into how to elicit a notification after a script completed and came across a rather hilarious Reddit thread here: https://www.reddit.com/r/PowerShell/comments/q8l24k/some_powershell_beep/
I adjusted a couple but all credit goes to the commenters in that thread and the laughs they brought me, and hopefully now you.
I will be sharing a script soon that contains the real use case that lead me to this discovery, but in the mean time give these a listen in your own PowerShell console.
NOTE: The 'notes' are at best a rough guess 😆
Seven Nation Army by The White Stripes
[System.Console]::Beep(196,1200);
[System.Console]::Beep(196,300);
[System.Console]::Beep(220,400);
[System.Console]::Beep(196,400);
[System.Console]::Beep(174,300);
[System.Console]::Beep(155,1000);
[System.Console]::Beep(146,1000);
[System.Console]::Beep(196,1000);
[System.Console]::Beep(196,300);
[System.Console]::Beep(220,400);
[System.Console]::Beep(196,400);
[System.Console]::Beep(174,300);
[System.Console]::Beep(155,400);
[System.Console]::Beep(174,300);
[System.Console]::Beep(155,400);
[System.Console]::Beep(146,1000);
Rick Roll
[System.Console]::Beep(523.25 ,150);
[System.Console]::Beep(587.33 ,150);
[System.Console]::Beep(698.46 ,150);
[System.Console]::Beep(587.33 ,150);
[System.Console]::Beep(880.00 ,450);
[System.Console]::Beep(880.00 ,450);
[System.Console]::Beep(783.99 ,1000);
[System.Console]::Beep(523.25 ,150);
[System.Console]::Beep(587.33 ,150);
[System.Console]::Beep(698.46 ,150);
[System.Console]::Beep(587.33 ,150);
[System.Console]::Beep(783.99 ,450);
[System.Console]::Beep(783.99 ,450);
[System.Console]::Beep(698.46 ,450);
[System.Console]::Beep(659.25 ,150);
[System.Console]::Beep(587.33 ,300);
[System.Console]::Beep(523.25 ,150);
[System.Console]::Beep(587.33 ,150);
[System.Console]::Beep(698.46 ,150);
[System.Console]::Beep(587.33 ,150);
[System.Console]::Beep(698.46 ,600);
[System.Console]::Beep(783.99 ,300);
[System.Console]::Beep(659.25 ,300);
[System.Console]::Beep(587.33 ,125);
[System.Console]::Beep(523.25 ,600);
[System.Console]::Beep(523.25 ,300);
[System.Console]::Beep(783.99 ,600);
[System.Console]::Beep(698.46 ,800);
Halloween Soundtrack
This one takes advantage of some looping for added effect
for($i=0;$i -le 15; $i++) {
$noteLength = 200
if ($i%8 -in (6,7)) {
$note1=1046
$note2=699
$note3=1109
} else {
$note1=1109
$note2=740
$note3=1175
}
[System.Console]::Beep($note1,$noteLength);
[System.Console]::Beep($note2,$noteLength);
[System.Console]::Beep($note2,$noteLength);
[System.Console]::Beep($note1,$noteLength);
[System.Console]::Beep($note2,$noteLength);
[System.Console]::Beep($note2,$noteLength);
[System.Console]::Beep($note1,$noteLength);
[System.Console]::Beep($note2,$noteLength);
[System.Console]::Beep($note3,$noteLength);
[System.Console]::Beep($note2,$noteLength);
}
Happy Birthday
This one builds on the concept.
$noteA = "1188.995"
$noteB = "1334.601"
$noteC = "1413.961"
$noteD = "1587.117"
$noteE = "1781.479"
$noteF = "1887.411"
$noteLowG = "1059.274"
$noteHighG = "2118.547"
$BeepList = @(
@{ Pitch = $noteLowG; Length = 300; };
@{ Pitch = $noteLowG; Length = 200; };
@{ Pitch = $noteA; Length = 500; };
@{ Pitch = $noteLowG; Length = 500; };
@{ Pitch = $noteC; Length = 500; };
@{ Pitch = $noteB; Length = 950; };
@{ Pitch = $noteLowG; Length = 300; };
@{ Pitch = $noteLowG; Length = 200; };
@{ Pitch = $noteA; Length = 500; };
@{ Pitch = $noteLowG; Length = 500; };
@{ Pitch = $noteD; Length = 500; };
@{ Pitch = $noteC; Length = 950; };
@{ Pitch = $noteLowG; Length = 300; };
@{ Pitch = $noteLowG; Length = 200; };
@{ Pitch = $noteHighG; Length = 500; };
@{ Pitch = $noteE; Length = 500; };
@{ Pitch = $noteC; Length = 500; };
@{ Pitch = $noteB; Length = 500; };
@{ Pitch = $noteA; Length = 500; };
@{ Pitch = $noteF; Length = 300; };
@{ Pitch = $noteF; Length = 200; };
@{ Pitch = $noteE; Length = 500; };
@{ Pitch = $noteC; Length = 500; };
@{ Pitch = $noteD; Length = 500; };
@{ Pitch = $noteC; Length = 900; };
);
# You can modify the variable $num_Loop for your convenience
$num_Loop = 2;
Foreach ($i in 1..$num_Loop) {
foreach ($Beep in $BeepList) {
[System.Console]::Beep($Beep['Pitch'], $Beep['Length']);
}
}
These are also available on my GitHub page here: https://github.com/taylordhendricks/thehelplessdesk/tree/main/powershell/music