From 25007b460b3a462b8ad6c8a4814f8c0815d5429d Mon Sep 17 00:00:00 2001 From: carlos815 <30379002+carlos815@users.noreply.github.com> Date: Wed, 14 Sep 2022 14:56:37 -0500 Subject: [PATCH] Create Cycle-Audio-Devices.ps1 --- EXAMPLE/Cycle-Audio-Devices.ps1 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 EXAMPLE/Cycle-Audio-Devices.ps1 diff --git a/EXAMPLE/Cycle-Audio-Devices.ps1 b/EXAMPLE/Cycle-Audio-Devices.ps1 new file mode 100644 index 0000000..4fd3f5a --- /dev/null +++ b/EXAMPLE/Cycle-Audio-Devices.ps1 @@ -0,0 +1,30 @@ +# This script cycles through all audio devices + + +# Get a list of all enabled devices +[System.Collections.ArrayList]$audioDevicesList = Get-AudioDevice -List + +# Get the default playback device as +$defaultPlaybackDevice = Get-AudioDevice -Playback + +#Remove non-playback devices from audioDevicesList +for ( $index = 0; $index -lt $audioDevicesList.count; $index++ ) { + if ($audioDevicesList[$index].type -ne "Playback") { + $audioDevicesList.Remove($audioDevicesList[$index]) + } +} + +#Loop through audioDevicesList +for ( $index = 0; $index -lt $audioDevicesList.count; $index++ ) { + #Find the position of the default audio device + if ( $audioDevicesList[$index].name -eq $defaultPlaybackDevice.name) { + #If it's the last device set the first audio device as the default + if ( $index -eq $audioDevicesList.count - 1) { + Set-AudioDevice -ID $audioDevicesList[0].id + } + #Otherwhise set the next audio device on the list as default + else { + Set-AudioDevice -ID $audioDevicesList[$index + 1].id + } + } +}