AudioDeviceCmdlets icon indicating copy to clipboard operation
AudioDeviceCmdlets copied to clipboard

Retrieve audio adapter and endpoint device names separately

Open upthekhyber opened this issue 1 year ago • 4 comments

When running Get-AudioDevice -List, the returned device name strings are a combination of both the audio adapter and the endpoint device names, formatted as "Endpoint device name (Audio adapter name)".

Is it possible to retrieve both names separately/independently (I'm actually only interested in the audio adapter name)?

upthekhyber avatar Sep 01 '24 18:09 upthekhyber

That's obtainable using built-in PowerShell methods for sting manipulation. Hopefully this helps:

# Load the "Name" results from the query into a list
$audio_list = Get-AudioDevice -List | Select-Object -ExpandProperty "Name"

# iterate over the list for each result from the query
foreach ($line in $audio_list) {
    # Find the first space followed by an open parenthesis
    $audio_device = $line -Split " \("
    # Only keep what's after the first space followed by open parenthesis, which is the adapter name
    $audio_device = $audio_device[-1]
    # Print the result without the last character, which is the closed parenthesis
    Write-Output $audio_device.Substring(0, $audio_device.Length -1)
}

mefranklin6 avatar Sep 04 '24 16:09 mefranklin6

That's obtainable using built-in PowerShell methods for sting manipulation.

Unfortunately, this is not reliable because the endpoint device name itself can contain parentheses.

upthekhyber avatar Sep 04 '24 17:09 upthekhyber

only if there's a space before the parenthesis, which I haven't come across. Usually it's something like "Intel(R)"

This may be more robust though as it can handle a string with multiple "space then open parenthesis" occurrences in it.

$audio_list = Get-AudioDevice -List | Select-Object -ExpandProperty "Name"

foreach ($line in $audio_list) {
    $audio_device_fragments = $line -split " \("
   
    $audio_device = $null
    if ($audio_device_fragments.Length -eq 2) {
        $audio_device = $audio_device_fragments[-1].TrimEnd(')')
    }
    elseif ($audio_device_fragments.Length -ge 3) {
        $audio_device = ($audio_device_fragments[1..($audio_device_fragments.Length - 1)] -join '(').TrimEnd(')')
    }

    Write-Output $audio_device
}

Also I'm not saying it's not a valid feature request, just trying to give back to this repo that I use extensively and help out where I can :)

mefranklin6 avatar Sep 04 '24 23:09 mefranklin6

I was wondering about this too. It's a bit strange that they are concatenated, and not in their own table columns, when they probably are different elsewhere.

Would have been great to have separate columns as Endpoint Device and Audio Adapter, or something like that.

Please note that there is also an additional "index" number in the Audio Adapter name, when there are multiple available devices of the same "Type".

eabase avatar Nov 10 '24 07:11 eabase