windowspowershellaudiocommand-linescripting

How to Set Microphone Volume to 100% in PowerShell or Command Line?


I'm trying to adjust the microphone volume to a specific level (e.g., 100) using PowerShell or the command line on Windows 11. I need a reliable method that can be executed programmatically without third-party applications.

I would like to adjust the first bar "VoiceMeeter Output" : VoiceMeeter Output Level

Here’s what I’ve tried so far:

  1. Using PowerShell with WMI Classes I attempted to manipulate audio settings using WMI classes, but encountered issues with non-existent classes and methods:

    $AudioEndpointDevices = [wmiclass]"ROOT\CIMV2:Win32_PerfRawData_Counters_AudioEndpoint"
    

    This resulted in an error: "Impossible de convertir la valeur «ROOT\CIMV2:Win32_PerfRawData_Counters_AudioEndpoint» en type « System.Management.ManagementClass». Erreur: «Non trouvé »" with the message that the WMI class could not be found.

  2. Using the AudioDeviceCmdlets Module I successfully listed and retrieved the audio devices using Get-AudioDevice, but found no available command like Set-AudioDeviceVolume to set the volume:

    Get-AudioDevice -List | Where-Object { $_.Type -eq "Recording" }
    

    This step worked fine, but I couldn't proceed to set the volume.

Given these challenges, does anyone have a working solution to programmatically set the microphone volume using native PowerShell commands or another command-line approach on Windows? I would prefer to avoid third-party tools if possible, but I'm open to using small utilities if they're the only solution.


Solution

  • Ok thanks @js2010.

    After a closer look at the AudioDeviceCmdlets documentation on GitHub, I realized I was quite close to the solution with my second approach. It became clear that the task needed to be done in two steps: first, selecting the ID of the audio device, and then performing the desired operation on it. Here's the complete powershell script that sets the microphone volume to 100%:

    # Script to set microphone volume to 100% using PowerShell
    
    # Import the necessary module
    Import-Module AudioDeviceCmdlets
    
    # Specify the device by its ID
    $microphoneId = "{0.0.1.00000000}.{a849033f-716e-4d33-80cc-9c5f49b913ba}"
    
    # Select the specific microphone
    Set-AudioDevice -Id $microphoneId
    
    # Set the microphone volume to 100%
    Set-AudioDevice -RecordingCommunicationVolume 100
    
    # Confirmation output
    Write-Output "The microphone volume has been set to 100%."