If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
  Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
  exit
}

$cm_drivers = Get-WindowsDriver -Online | Where-Object {$_.ProviderName -eq "C-Media"}
$win_audio_srv = Get-Service | Where-Object {$_.Name -eq "Audiosrv"}

if ($win_audio_srv.Status -eq "Running") {
    Write-Host "Stop Audio Service"
    Stop-Service -InputObject Audiosrv -Force
}

foreach ($driver_found in $cm_drivers) {
    if ($driver_found.OriginalFileName -match "G600.Inf") {
        $cm_tmpdrv = $driver_found
        Write-Host "C-Media Driver Version: $($cm_tmpdrv.Version) $(($cm_tmpdrv.Date).ToString("yyyy/MM/dd"))"
		pnputil /delete-driver $($cm_tmpdrv.Driver) /uninstall | out-null
		Write-Host "Removed..."
		continue
    }
}

Write-Host "Re-start Audio Service"

Start-Service Audiosrv

Write-Host "Uninstall completed"