frgnca / AudioDeviceCmdlets

AudioDeviceCmdlets is a suite of PowerShell Cmdlets to control audio devices on Windows
MIT License
737 stars 92 forks source link

Get-AudioDevice -List error when no enabled mic or playback device. #50

Closed chetmcmasterson closed 2 years ago

chetmcmasterson commented 2 years ago

I'm seeing behavior where Get-AudioDevice -List works iff there is at least one playback device AND one recording device enabled. I didn't have a mic enabled and it took some work to figure out that that was causing the error. Error below:

PS C:\WINDOWS\system32> Get-AudioDevice -List Get-AudioDevice : Element not found. (Exception from HRESULT: 0x80070490) At line:1 char:1

frgnca commented 2 years ago

Get-AudioDevice -List works iff there is at least one playback device AND one recording device enabled. I didn't have a mic enabled and it took some work to figure out that that was causing the error.

Thank you for that information. Indeed I remember in my testing I always happened to have at least one of each.

frgnca commented 2 years ago

I think the issue must be on line 167 when calling the List parameter, with the possibility to also happen on line 193 and line 220 when calling the ID and Index parameter respectively.

The way it is currently done in these lines is calling the CoreAudioApi function GetDefaultAudioEndpoint() to get a value to compare directly instead of elsewhere and possibly in a TryCatch.

frgnca commented 2 years ago

Will follow up this bug in issue #35