Created
February 26, 2022 09:21
-
-
Save alexmags/6a28c874e88786fddedd2c1efbd78096 to your computer and use it in GitHub Desktop.
Muzak for long running PowerShell scripts. Pointless
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
$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent # files relative to here | |
$musakFilePath="$scriptDir\musak.mp3" # https://www.youtube.com/watch?v=FsoIfkNQYEg | |
$wmplayer = New-Object System.Windows.Media.MediaPlayer | |
$wmplayer.Open($musakFilePath) | |
Start-Sleep 2 # This allows the $wmplayer time to load the audio file | |
$duration = $wmplayer.NaturalDuration.TimeSpan.TotalSeconds | |
$wmplayer.Play() | |
$stopwatch=[system.diagnostics.stopwatch]::StartNew() | |
while ($stopwatch.Elapsed.Seconds -lt $duration) | |
{ | |
Write-Progress -Activity "Doing stuff, please hold…" -status "$($stopwatch.Elapsed.Seconds) seconds" -percentComplete ($stopwatch.Elapsed.Seconds / $duration*100) | |
# do something | |
# break when done | |
start-Sleep -s 1 | |
} | |
$wmplayer.Stop() | |
$wmplayer.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment