Skip to content

Instantly share code, notes, and snippets.

@diogomartino
Last active June 17, 2023 12:33
Show Gist options
  • Save diogomartino/6198d2fc4496953c01cc1bff56159726 to your computer and use it in GitHub Desktop.
Save diogomartino/6198d2fc4496953c01cc1bff56159726 to your computer and use it in GitHub Desktop.
Set default audio device powershell script
# This script is for Steelseries headphones users, but you can change it to meet your goal
# Before running this you need to install the required module
# Run this in powershell as administrator:
# Install-Module -Name AudioDeviceCmdlets
# Check if module is installed
$moduleName = "AudioDeviceCmdlets"
$moduleInstalled = Get-Module -ListAvailable | Where-Object {$_.Name -eq $moduleName}
if ($moduleInstalled) {
Write-Output "The '$moduleName' module is installed."
}
else {
Write-Output "The '$moduleName' module is not installed. Please install it before running this script."
}
# Target device (with no sonar)
$deviceName = "* (SteelSeries Arctis 9 Game)"
$device = Get-PnpDevice -Class "AudioEndpoint" | Where-Object {$_.FriendlyName -like "* (SteelSeries Arctis 9 Game)" -and ($_.Status -eq "OK")}
if ($device -ne $null) {
$deviceId = $device.DeviceId.Split("\") | Select-Object -Last 1
Write-Output "Enabling '$deviceName'"
Set-AudioDevice -ID $deviceId
Write-Output "Successfully set '$deviceName' as the default audio device."
}
else {
Write-Output "Could not find audio device with name '$deviceName'. Make sure the device is installed and try again."
}
# Disable all sonar outputs (including the microphone)
# Does not always work
# Windows being windows
# Comment the exit if want that behaviour
exit
$deviceName = "Steelseries Sonar -*"
$devices = Get-WmiObject -Class Win32_PnPEntity | Where-Object {$_.Name -like "*audio*" -and $_.Name -like $deviceName}
Write-OutPut "Found $($devices.Count) devices with name '$deviceName'"
foreach ($device in $devices) {
# check if device is ok and enabled
if ($device.Status -eq "OK" -and $device.Enabled -eq $true) {
Write-Output "Disabling '$($device.Name)'"
$device.Disable()
Write-Output "Successfully disabled '$($device.Name)'."
}
else {
Write-Output "Device '$($device.Name)' is not enabled or is not OK."
}
}
# Enable microphone
$deviceName = "*Steelseries Sonar - Microphone*"
$device = Get-WmiObject -Class Win32_PnPEntity | Where-Object {$_.Name -like "*audio*" -and $_.Name -like $deviceName}
if ($device -ne $null) {
Write-Output "Enabling microphone '$deviceName'"
$device.Enable()
Write-Output "Successfully enabled microphone '$deviceName'."
}
else {
Write-Output "Could not find microphone with name '$deviceName'. Make sure the device is installed and try again."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment