51 lines
2.1 KiB
PowerShell
51 lines
2.1 KiB
PowerShell
function RunAsAdmin($scriptPath) {
|
||
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
|
||
$admin = [Security.Principal.WindowsBuiltInRole]::Administrator
|
||
if (!$principal.IsInRole($admin)) {
|
||
$arguments = "& '" + $scriptPath + "'"
|
||
Start-Process powershell -Verb runAs -ArgumentList $arguments
|
||
exit
|
||
}
|
||
}
|
||
|
||
function GenerateDeviceList($devManViewPath, $outputFile) {
|
||
& $devManViewPath /scomma $outputFile
|
||
Write-Host "Created $outputFile"
|
||
}
|
||
|
||
function FilterDevices($deviceListFile, $pattern) {
|
||
$deviceList = Import-Csv -Path $deviceListFile -Encoding UTF8 -Header "Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14", "Column15", "Column16", "Column17", "Column18", "Column19", "Column20", "Column21", "Column22", "Column23", "Column24", "Column25", "Column26", "Column27"
|
||
$deviceList | Select-Object -ExpandProperty Column1 | Where-Object { $_ -match $pattern } | Sort-Object | Get-Unique
|
||
}
|
||
|
||
function UninstallDevices($devManViewPath, $devices) {
|
||
foreach ($device in $devices) {
|
||
Write-Host "Uninstalling $device"
|
||
& $devManViewPath /uninstall "$device"
|
||
}
|
||
}
|
||
|
||
# 读取配置文件
|
||
|
||
|
||
# 配置选项,当选项不起作用时,检查DevManView.cfg中是否配置了filter
|
||
$scriptPath = $myinvocation.mycommand.definition
|
||
$config = Get-Content -Path $scriptPath\..\config.json | ConvertFrom-Json
|
||
$devManViewPath = $config.devManViewPath
|
||
$deviceListFile = $config.deviceListFile
|
||
$pattern = $config.pattern
|
||
|
||
# 执行
|
||
RunAsAdmin $scriptPath
|
||
GenerateDeviceList $devManViewPath $deviceListFile
|
||
$devices = FilterDevices $deviceListFile $pattern
|
||
UninstallDevices $devManViewPath $devices
|
||
Remove-Item $deviceListFile
|
||
|
||
# 重启 Adobe Audition and Audacity
|
||
Stop-Process -Name "Audition" -Force -ErrorAction SilentlyContinue
|
||
Start-Process -FilePath $config.auditionPath
|
||
Stop-Process -Name "Audacity" -Force -ErrorAction SilentlyContinue
|
||
Start-Process -FilePath $config.audacityPath
|