@echo off
call :setting
Set keyword=AMDPCIDev.cat
call :dr_ps1

Set keyword=amdpsp.cat
call :dr_ps1

Set keyword=SMbusamd.cat
call :dr_ps1

Set keyword=amdgpio2.cat
call :dr_ps1

Set keyword=AmdMicroPEP.cat
call :dr_ps1

Set keyword=amdwirelessbutton.cat
call :dr_ps1

Set keyword=amdi2c.cat
call :dr_ps1

Set keyword=amduart.cat
call :dr_ps1

Set keyword=AmdIOV.cat
call :dr_ps1


::Not change below script=============================================================================================
::====================================================================================================================
if exist %ps_dr% powershell -executionpolicy bypass -file "%ps_dr%"
echo Dr ReturnCode [%errorlevel%] 
echo ==========================================================================================
echo ==========================================================================================
if exist %ps_uwp% powershell -executionpolicy bypass -file "%ps_uwp%"
echo UWP ReturnCode [%errorlevel%] 
echo ==========================================================================================
echo ==========================================================================================
goto :del_ps1

:dr_ps1
echo $keyword ="%keyword%" >>%ps_dr%
echo echo $keyword >>%ps_dr%
echo $y= ls -r -path C:\Windows\Inf -filter oem*.inf ^|?{$_ ^| select-string -pattern $keyword -SimpleMatch}^| select -exp name >>%ps_dr%
echo if($y -eq $null){throw 'No oem*.inf'} >>%ps_dr%
echo $y ^| foreach { >>%ps_dr%
echo Get-content C:\Windows\INF\$_ -TotalCount ((Select-String -Path C:\Windows\INF\$_ -Pattern '[Version]' -SimpleMatch).LineNumber+8) >>%ps_dr%
echo Read-Host "Push any key to uninstall[$_]-keyword[$keyword]:" >>%ps_dr%
echo pnputil /delete-driver $_ /uninstall /force >>%ps_dr%
echo write-host ========================================================================================== >>%ps_dr%
echo } >>%ps_dr%
Set keyword=
echo. >>%ps_dr%
exit /b

:uwp_ps1
echo $uwpkeyword="%uwpkeyword%" >>%ps_uwp%
echo $a=Get-ProvisionedAppPackage -Online ^| foreach{if($_.displayname -match $uwpkeyword) >>%ps_uwp%
echo {$_ }>>%ps_uwp%
echo }>>%ps_uwp%
echo if($uwpkeyword -eq $null){exit}>>%ps_uwp%
echo if($a -eq $null){throw 'No UWP package [$uwpkeyword]' }>>%ps_uwp%
echo Read-Host "Push any key to uninstall[$($a.PackageName)]-keyword[$uwpkeyword]">>%ps_uwp%
echo Remove-ProvisionedAppPackage -PackageName $a.PackageName -Online -AllUsers -Verbose>>%ps_uwp%
echo write-host ========================================================================================== >>%ps_uwp%
Set uwpkeyword=
echo. >>%ps_uwp%
exit /b

:setting
title %~xn0
cd /d %~dp0
Set ps_dr=UnInstall_Dr.ps1
Set ps_uwp=UnInstall_UWP.ps1
if exist %ps_dr% del %ps_dr%
if exist %ps_uwp% del %ps_uwp%
echo #Driver >%ps_dr%
echo #UWP APP >%ps_uwp%

echo Select within 5 sec
choice /C YN /M "Driver_UWP uninstall Keep ps1 script? (Y/N)(N Default)" /t 5 /d N

if %errorlevel% EQU 1 Set keep_ps1=Y
if %errorlevel% EQU 2 Set keep_ps1=N
echo Keep PS1 script: %keep_ps1%
exit /b

:del_ps1
@echo off
if %keep_ps1% equ Y goto :end
if exist %ps_dr% del %ps_dr%
if exist %ps_uwp% del %ps_uwp%

:end
timeout 5
:: 2020/4/17 V1 release