Friday, July 26, 2019

Best PowerShell Functions & Scripts Ever!

So you want to jazz up your scripts … check out these great additions

Basic Beep

#beep

[console]::beep(440,500)

#scale

$scale=@{
MidC=261.6
CSharp=277.2
D=293.7
DSharp=311.1
E=329.6
F=349.2
FSharp=370.0
G=392.0
GSharp=415.3
A=440.0
ASharp=466.2
B=493.9
C=523.2
}

#play a chromatic scale
write-host “First octave” -ForegroundColor Cyan
$scale.values | sort | foreach {[console]::beep($_,125)}

Basic Music

# Star Wars

Function Play-StarWars {
      [console]::beep(440,500)
      [console]::beep(440,500)
      [console]::beep(440,500)
      [console]::beep(349,350)
      [console]::beep(523,150)
      [console]::beep(440,500)
      [console]::beep(349,350)
      [console]::beep(523,150)
      [console]::beep(440,1000)
      [console]::beep(659,500)
      [console]::beep(659,500)
      [console]::beep(659,500)
      [console]::beep(698,350)
      [console]::beep(523,150)
      [console]::beep(415,500)
      [console]::beep(349,350)
      [console]::beep(523,150)
      [console]::beep(440,1000)
}

Play-StarWars

#imperial march

Function Play-ImperialMarch{

[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)

[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)

[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(698,350)
[console]::beep(523,150)

[console]::beep(415,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)

[console]::beep(880,500)
[console]::beep(440,350)
[console]::beep(440,150)
[console]::beep(880,500)
[console]::beep(830,250)
[console]::beep(784,250)

[console]::beep(740,125)
[console]::beep(698,125)
[console]::beep(740,250)

[console]::beep(455,250)
[console]::beep(622,500)
[console]::beep(587,250)
[console]::beep(554,250)

[console]::beep(523,125)
[console]::beep(466,125)
[console]::beep(523,250)

[console]::beep(349,125)
[console]::beep(415,500)
[console]::beep(349,375)
[console]::beep(440,125)

[console]::beep(523,500)
[console]::beep(440,375)
[console]::beep(523,125)
[console]::beep(659,1000)

[console]::beep(880,500)
[console]::beep(440,350)
[console]::beep(440,150)
[console]::beep(880,500)
[console]::beep(830,250)
[console]::beep(784,250)

[console]::beep(740,125)
[console]::beep(698,125)
[console]::beep(740,250)

[console]::beep(455,250)
[console]::beep(622,500)
[console]::beep(587,250)
[console]::beep(554,250)

[console]::beep(523,125)
[console]::beep(466,125)
[console]::beep(523,250)

[console]::beep(349,250)
[console]::beep(415,500)
[console]::beep(349,375)
[console]::beep(523,125)

[console]::beep(440,500)
[console]::beep(349,375)
[console]::beep(261,125)
[console]::beep(440,1000)

}

Play-ImperialMarch

# Mission Impossible

Function Play-MissionImpossible{

[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(932,150)
Start-Sleep -m 150
[console]::beep(1047,150)
Start-Sleep -m 150
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(699,150)
Start-Sleep -m 150
[console]::beep(740,150)
Start-Sleep -m 150
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(932,150)
Start-Sleep -m 150
[console]::beep(1047,150)
Start-Sleep -m 150
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(784,150)
Start-Sleep -m 300
[console]::beep(699,150)
Start-Sleep -m 150
[console]::beep(740,150)
Start-Sleep -m 150
[console]::beep(932,150)
[console]::beep(784,150)
[console]::beep(587,1200)
Start-Sleep -m 75
[console]::beep(932,150)
[console]::beep(784,150)
[console]::beep(554,1200)
Start-Sleep -m 75
[console]::beep(932,150)
[console]::beep(784,150)
[console]::beep(523,1200)
Start-Sleep -m 150
[console]::beep(466,150)
[console]::beep(523,150)

}

Play-MissionImpossible

# Mario

Function Play-Mario{

$i = 1

do {Write-Host $i; $i++

[console]::beep(659,250) ##E

[console]::beep(659,250) ##E

[console]::beep(659,300) ##E

[console]::beep(523,250) ##C

[console]::beep(659,250) ##E

[console]::beep(784,300) ##G

[console]::beep(392,300) ##g

[console]::beep(523,275) ## C

[console]::beep(392,275) ##g

[console]::beep(330,275) ##e

[console]::beep(440,250) ##a

[console]::beep(494,250) ##b

[console]::beep(466,275) ##a#

[console]::beep(440,275) ##a

[console]::beep(392,275) ##g

[console]::beep(659,250) ##E

[console]::beep(784,250) ## G

[console]::beep(880,275) ## A

[console]::beep(698,275) ## F

[console]::beep(784,225) ## G

[console]::beep(659,250) ## E

[console]::beep(523,250) ## C

[console]::beep(587,225) ## D

[console]::beep(494,225) ## B

}

until ($i -gt 1)

}

Play-Mario

Advanced Music

# Mario Long Version

function Play-Mario-Long {

function b($a,$b){
     [console]::beep($a,$b)
}
function s($a){
     sleep -m $a
}
write-host "Super Mario!"
b 660 100;
s 150;
b 660 100;
s 300;
b 660 100;
s 300;
b 510 100;
s 100;
b 660 100;
s 300;
b 770 100;
s 550;
b 380 100;
s 575;

b 510 100;
s 450;
b 380 100;
s 400;
b 320 100;
s 500;
b 440 100;
s 300;
b 480 80;
s 330;
b 450 100;
s 150;
b 430 100;
s 300;
b 380 100;
s 200;
b 660 80;
s 200;
b 760 50;
s 150;
b 860 100;
s 300;
b 700 80;
s 150;
b 760 50;
s 350;
b 660 80;
s 300;
b 520 80;
s 150;
b 580 80;
s 150;
b 480 80;
s 500;

b 510 100;
s 450;
b 380 100;
s 400;
b 320 100;
s 500;
b 440 100;
s 300;
b 480 80;
s 330;
b 450 100;
s 150;
b 430 100;
s 300;
b 380 100;
s 200;
b 660 80;
s 200;
b 760 50;
s 150;
b 860 100;
s 300;
b 700 80;
s 150;
b 760 50;
s 350;
b 660 80;
s 300;
b 520 80;
s 150;
b 580 80;
s 150;
b 480 80;
s 500;

b 500 100;
s 300;

b 760 100;
s 100;
b 720 100;
s 150;
b 680 100;
s 150;
b 620 150;
s 300;

b 650 150;
s 300;
b 380 100;
s 150;
b 430 100;
s 150;

b 500 100;
s 300;
b 430 100;
s 150;
b 500 100;
s 100;
b 570 100;
s 220;

b 500 100;
s 300;

b 760 100;
s 100;
b 720 100;
s 150;
b 680 100;
s 150;
b 620 150;
s 300;

b 650 200;
s 300;

b 1020 80;
s 300;
b 1020 80;
s 150;
b 1020 80;
s 300;

b 380 100;
s 300;
b 500 100;
s 300;

b 760 100;
s 100;
b 720 100;
s 150;
b 680 100;
s 150;
b 620 150;
s 300;

b 650 150;
s 300;
b 380 100;
s 150;
b 430 100;
s 150;

b 500 100;
s 300;
b 430 100;
s 150;
b 500 100;
s 100;
b 570 100;
s 420;

b 585 100;
s 450;

b 550 100;
s 420;

b 500 100;
s 360;

b 380 100;
s 300;
b 500 100;
s 300;
b 500 100;
s 150;
b 500 100;
s 300;

b 500 100;
s 300;

b 760 100;
s 100;
b 720 100;
s 150;
b 680 100;
s 150;
b 620 150;
s 300;

b 650 150;
s 300;
b 380 100;
s 150;
b 430 100;
s 150;

b 500 100;
s 300;
b 430 100;
s 150;
b 500 100;
s 100;
b 570 100;
s 220;

b 500 100;
s 300;

b 760 100;
s 100;
b 720 100;
s 150;
b 680 100;
s 150;
b 620 150;
s 300;

b 650 200;
s 300;

b 1020 80;
s 300;
b 1020 80;
s 150;
b 1020 80;
s 300;

b 380 100;
s 300;
b 500 100;
s 300;

b 760 100;
s 100;
b 720 100;
s 150;
b 680 100;
s 150;
b 620 150;
s 300;

b 650 150;
s 300;
b 380 100;
s 150;
b 430 100;
s 150;

b 500 100;
s 300;
b 430 100;
s 150;
b 500 100;
s 100;
b 570 100;
s 420;

b 585 100;
s 450;

b 550 100;
s 420;

b 500 100;
s 360;

b 380 100;
s 300;
b 500 100;
s 300;
b 500 100;
s 150;
b 500 100;
s 300;

b 500 60;
s 150;
b 500 80;
s 300;
b 500 60;
s 350;
b 500 80;
s 150;
b 580 80;
s 350;
b 660 80;
s 150;
b 500 80;
s 300;
b 430 80;
s 150;
b 380 80;
s 600;

b 500 60;
s 150;
b 500 80;
s 300;
b 500 60;
s 350;
b 500 80;
s 150;
b 580 80;
s 150;
b 660 80;
s 550;

b 870 80;
s 325;
b 760 80;
s 600;

b 500 60;
s 150;
b 500 80;
s 300;
b 500 60;
s 350;
b 500 80;
s 150;
b 580 80;
s 350;
b 660 80;
s 150;
b 500 80;
s 300;
b 430 80;
s 150;
b 380 80;
s 600;

b 660 100;
s 150;
b 660 100;
s 300;
b 660 100;
s 300;
b 510 100;
s 100;
b 660 100;
s 300;
b 770 100;
s 550;
b 380 100;
s 575;
}

Play-Mario-Long

# Christmas Music Jingle Bells

Function Play-JingleBells{

$Notes = New-Object -TypeName psobject -Property @{
     REST    = 0
     GbelowC = 196
     A       = 220
     Asharp  = 233
     B       = 247
     C       = 262
     Csharp  = 277
     D       = 294
     Dsharp  = 311
     E       = 330
     F       = 349
     Fsharp  = 370
     G       = 392
     Gsharp  = 415
     AA      = 440
     AAsharp = 466
     BB      = 493
     CC      = 523
     CCsharp = 554
     DD      = 587
     DDsharp = 622
     EE      = 659
     FF      = 698
     FFsharp = 740
     GG      = 784
     GGsharp = 830
     }
 
$Duration = New-Object -TypeName psobject -Property @{
     WHOLE     = 1600
     HALF      = 800
     QUARTER   = 400
     EIGHTH    = 200
     SIXTEENTH = 100
     }
 
 
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.QUARTER)
[console]::beep($Notes.C, $Duration.HALF   )
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.QUARTER)
[console]::beep($Notes.D, $Duration.HALF   )
Start-Sleep -m $Duration.EIGHTH
[console]::beep($Notes.D, $Duration.EIGHTH )
[console]::beep($Notes.E, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
 
[console]::beep($Notes.E, $Duration.HALF)
Start-Sleep -m $Duration.EIGHTH
[console]::beep($Notes.E, $Duration.EIGHTH)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.HALF)
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.QUARTER)
[console]::beep($Notes.C, $Duration.HALF   )
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.EIGHTH )
[console]::beep($Notes.C, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.QUARTER)
[console]::beep($Notes.D, $Duration.HALF   )
Start-Sleep -m $Duration.QUARTER
[console]::beep($Notes.D, $Duration.EIGHTH )
 
 
[console]::beep($Notes.E, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.EIGHTH)
[console]::beep($Notes.DD, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.HALF)
[console]::beep($Notes.CC, $Duration.HALF)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.HALF)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.HALF)
 
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.EIGHTH)
[console]::beep($Notes.AA, $Duration.HALF)
Start-Sleep -m $Duration.EIGHTH
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.EIGHTH)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.EIGHTH)
[console]::beep($Notes.AA, $Duration.EIGHTH)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.HALF)
[console]::beep($Notes.CC, $Duration.HALF)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.HALF)
 
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.HALF)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.EIGHTH)
[console]::beep($Notes.AA, $Duration.HALF)
Start-Sleep -m $Duration.EIGHTH
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.EIGHTH)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.QUARTER)
[console]::beep($Notes.AA, $Duration.EIGHTH)
[console]::beep($Notes.AA, $Duration.EIGHTH)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.CC, $Duration.QUARTER)
[console]::beep($Notes.BB, $Duration.QUARTER)
[console]::beep($Notes.G, $Duration.QUARTER)
[console]::beep($Notes.F, $Duration.HALF)
}

Play-JingleBells

# Turkish Anthem

powershell.exe -enc JABhAD0AMgA5ADMALAA0ADQAMAAsADQANAAwACwANAA0ADAALAA0ADQAMAAsADQANAAwACwANAA0ADAALAA0ADYANgAsADQANAAwACwAMwA5ADIALAA0ADYANgAsADQANAAwACwAMgA5ADMALAA0ADQAMAAsADQANAAwACwANAA0ADAALAA0ADQAMAAsADQANAAwACwANAA0ADAALAA0ADYANgAsADQANAAwACwAMwA5ADIALAA0ADYANgAsADQANAAwACwANAA0ADAALAA1ADgANwAsADUAMgAzACwANAA2ADYALAA0ADQAMAAsADMAOQAyACwANAA0ADAALAAzADkAMgAsADMANAA5ACwAMwAyADkALAAzADQAOQAsADQANAAwACwAMgA5ADMALAA0ADQAMAAsADMAOQAyACwAMwA0ADkALAAzADIAOQAsADIAOQAzACwAMwA0ADkALAAzADIAOQAsADIAOQAzACwAMgA2ADEALAAyADkAMwA7ACQAYgA9ADgAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA5ADAAMAAsADgAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA5ADAAMAAsADgAMAAwACwAOAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwAOAAwADAALAA5ADAAMAAsADgAMAAwACwAOAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwANAAwADAALAA0ADAAMAAsADQAMAAwACwAOAAwADAAOwAkAGMAPQBAACgAMAAuAC4ANAA2ACkAOwAkAGMALgBGAG8AcgBFAGEAYwBoAHsAWwBDAG8AbgBzAG8AbABlAF0AOgA6AEIAZQBlAHAAKAAkAGEAWwAkAF8AXQAsACQAYgBbACQAXwBdACkAfQA=

References

https://medium.com/@bmerenler/powershell-intro-with-simple-beep-music-71535383e017

https://social.technet.microsoft.com/wiki/contents/articles/20989.music-from-the-command-line-performed-by-powershell.aspx