set default communication device windows 10 powershell

5,593

Solution 1

I never tried this in PowerShell, but I am using this from PowerShell:

nircmd.exe setdefaultsounddevice FrontHeadphones

where FrontHeadphones is the name of an audio device, you need NirSoft's nircmd for this.

Solution 2

Try the below, tweak as needed.

Switching Audio Input and Output With PowerShell

All the control panel dialog is doing under the hood is changing a few registry settings. What I wanted a script that would let me change from one profile to another.

$r = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$regRoot = "HKCU:\Software\Microsoft\"


$profiles = @{"Netbook" = @("Realtek HD Audio output",      
                            "Realtek HD Audio input");
            "Bluetooth" = @("Bluetooth Hands-free Audio", 
                            "Bluetooth Hands-free Audio") }

function Write-Message ( [string]$message )
{
    echo $message
    # Uncomment this line to show dialog outputs from -set 
    # $r = [System.Windows.Forms.MessageBox]::Show($message)
}

function Set-Mapping ( [string]$devOut, [string]$devIn )
{
    echo "Profile audio:`n  in  = $devIn`n  out = $devOut"

    $regKey = $regRoot + "\Multimedia\Sound Mapper\"
    Set-ItemProperty $regKey -name Playback -value $devOut
    Set-ItemProperty $regKey -name Record -value $devIn
}

function List-Devices
{
    $regKey = $regRoot + "\Windows\CurrentVersion\Applets\Volume Control\"
    echo "Sound devices:"
    ls $regKey | where { ! $_.Name.EndsWith("Options") } | 
        Foreach-Object { 
            echo ("  " + $_.Name.Substring($_.Name.LastIndexOf("\")+1)) 
        }
}

$cmd = $args[0]
switch ($cmd)
{
    "-profiles" 
    {
        echo "Sound profiles:"
        echo $profiles
    }
    "-devices"
    {
        List-Devices
    }
    "-set" 
    {
        $p = $args[1]
        if (!$profiles.ContainsKey($p)) {
            echo "No such profile: $p"
            echo $profiles
            exit
        }
        Set-Mapping $profiles.Get_Item($p)[0] $profiles.Get_Item($p)[1]
        Write-Message "Profile set to: $p"
    }
    default 
    { 
        Write-Message "No such option: $cmd" 
    }
}

As you can see it has three options:

-profiles – List the available sound profiles. -devices – List the sound devices. -set [profile] – Set the audio profile.

Share:
5,593
jensDL
Author by

jensDL

Updated on September 18, 2022

Comments

  • jensDL
    jensDL almost 2 years

    default communication device powershell.\

    is it possible to set audio device output als default communication device in powershell? i need this because i switch between my speakers and my headphones i already use AudioDeviceCmdlets in powershell to set an audio device as default output.

    i already tried doing it in de registry but powershell can't change a value in that specific part (i ran powershell in administator mode)

    with this i want to create a script that can see what device is turned off or on and then knows to switch to the speakers or to my headphones as output

    i already have this code:

    if((Get-PnpDevice -InstanceId 'INSTANCEID' | Select-Object -Property status) -eq "OK"){ Disable-PnpDevice -InstanceId 'INSTANCEID' -confirm:$false Enable-PnpDevice -InstanceId 'INSTANCEID' -confirm:$false } Else { Enable-PnpDevice -InstanceId 'INSTANCEID' -confirm:$false }

    default audio device output headphones GAME Set-AudioDevice -ID "deviceid"

    default audio device output Speakers Set-AudioDevice -ID "deviceid"

    tanks.

    • SimonS
      SimonS almost 4 years
      I think you should look into the AudioDeviceCmdlets which you can download here: github.com/frgnca/AudioDeviceCmdlets
    • Ravindra Bawane
      Ravindra Bawane almost 4 years
      What part of the registry were you trying to write to?
  • postanote
    postanote almost 4 years
    What did you search for? powershell set default audio device
  • jensDL
    jensDL almost 4 years
    this will set the device as default output and i need default communication output.