AudioDeviceCmdlets Documentation

repository·master·Indexed 21 days ago

https://github.com/frgnca/audiodevicecmdlets

A PowerShell module for granular control over Windows audio devices. It provides cmdlets to manage default playback and recording devices, adjust volume and mute states, and monitor audio output and input levels via Get-AudioDevice, Set-AudioDevice, and Write-AudioDevice.

Tokens
1.3K
Snippets
5
Records
5
Agent score
26%

What's inside AudioDeviceCmdlets

  1. Build AudioDeviceCmdlets from source

    master

    If you need to build the module from source, follow these steps:

    1. Prerequisites: Install Visual Studio 2022 with the .NET desktop development workload.
    2. Project Creation: Create a new project from the SOURCE folder using File -> New -> Project From Existing Code... (Type: Visual C#). Set the Output type to Class Library.
    3. Configuration:
      • Assembly name: AudioDeviceCmdlets
      • Target framework: .NET Framework 4.6.1+
    4. Dependencies: Install the Microsoft.PowerShell.5.1.ReferenceAssemblies NuGet package (v1.0.0+).
    5. Build: Set the solution configuration to Release and build the solution to generate AudioDeviceCmdlets.dll.
    6. Import: Copy the resulting .dll to your PowerShell modules directory and import it.
    # Example import steps after building
    $FilePath = "C:\Path\To\AudioDeviceCmdlets\SOURCE\bin\Release\AudioDeviceCmdlets.dll"
    New-Item "$($profile | split-path)\Modules\AudioDeviceCmdlets" -Type directory -Force
    Copy-Item $FilePath "$($profile | split-path)\Modules\AudioDeviceCmdlets\AudioDeviceCmdlets.dll"
    Set-Location "$($profile | Split-Path)\Modules\AudioDeviceCmdlets"
    Get-ChildItem | Unblock-File
    Import-Module AudioDeviceCmdlets
  2. Set audio device defaults and properties with Set-AudioDevice

    master

    Use Set-AudioDevice to change the default audio device (playback or recording) and its communication role. You can also control volume and mute states for default devices.

    # Set a specific device as both default and default communication
    Set-AudioDevice <AudioDevice>
    
    # Set a device as default communication only
    Set-AudioDevice <AudioDevice> -CommunicationOnly
    
    # Set a device as default playback only
    Set-AudioDevice <AudioDevice> -DefaultOnly
    
    # Toggle mute for the default playback device
    Set-AudioDevice -PlaybackMuteToggle
    
    # Set volume for the default recording device (0-100)
    Set-AudioDevice -RecordingVolume 50
    
    # Set mute state for the default communication playback device
    Set-AudioDevice -PlaybackCommunicationMute $true
  3. Get audio device information with Get-AudioDevice

    master

    Use Get-AudioDevice to retrieve information about audio devices. You can query by specific ID, Index, or use flags to get the default playback, recording, or communication devices and their current states (volume/mute).

    # Get a list of all enabled devices
    Get-AudioDevice -List
    
    # Get the default playback device
    Get-AudioDevice -Playback
    
    # Get the default playback device's volume (0-100)
    Get-AudioDevice -PlaybackVolume
    
    # Get the default playback device's mute state
    Get-AudioDevice -PlaybackMute
    
    # Get a specific device by ID or Index
    Get-AudioDevice -ID <string>
    Get-AudioDevice -Index <int>
  4. Monitor audio output and input with Write-AudioDevice

    master

    Use Write-AudioDevice to monitor the power output (meter) or the raw stream of data for playback or recording devices. This is useful for visualizing audio levels.

    # Get a meter of the default playback device's power output (0-100)
    Write-AudioDevice -PlaybackMeter
    
    # Get a stream of integers representing the default playback device's power output
    Write-AudioDevice -PlaybackStream
    
    # Get a meter of the default recording device's power output
    Write-AudioDevice -RecordingMeter