How to set default audio device from command line on Windows operating system

SoundVolumeView is a freeware tool for Windows which allows you to easily set the default audio device from command-line and GUI.
In order to set the default sound device, you have to run SoundVolumeView, and find the audio device that you want to set as default:

Let's say that you want to set 'Speakers' device in the above screenshot as the default, so the command to set the 'Speakers' device as default is:
SoundVolumeView.exe /SetDefault "Speakers" 0

The first parameter of /SetDefault command specifies the device name ("Speakers") and the second parameter specifies the default type. There are actually 3 type of default device you can set - Console (0) , Multimedia (1), and Communications (2). If you are not sure which type of default to use, simply try to first one (0) and if doesn't work as expected then try the others (1 and 2).

If there are multiple items with the same name, you have to use the string appeared under the 'Item ID' column or 'Command-Line Friendly ID' column in order to uniquely identify the correct sound device.
In the example of the above screenshot, you can use the 'Realtek High Definition Audio\Device\Speakers\Render' string to identify the device, for example:
SoundVolumeView.exe /SetDefault "Realtek High Definition Audio\Device\Speakers\Render" 0

If you want to switch the default between 2 devices, you can use the /SwitchDefault command, for example:
SoundVolumeView.exe /SwitchDefault "Realtek High Definition Audio\Device\Speakers\Render" "2- USB AUDIO\Device\Speakers\Render" 0

You can also use the above commands of SoundVolumeView to set the default capture device, like Microphone:
SoundVolumeView.exe /SetDefault "Microphone" 0

Be aware that SoundVolumeView works on any version of Windows, starting from Windows Vista and up to Windows 10. Windows XP is not supported.