Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve audio adapter and endpoint device names separately #80

Open
upthekhyber opened this issue Sep 1, 2024 · 4 comments
Open

Retrieve audio adapter and endpoint device names separately #80

upthekhyber opened this issue Sep 1, 2024 · 4 comments

Comments

@upthekhyber
Copy link

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)?

@mefranklin6
Copy link

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)
}

@upthekhyber
Copy link
Author

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.

@mefranklin6
Copy link

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 :)

@eabase
Copy link

eabase commented Nov 10, 2024

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants