Files
reload_xmos_device/reload_xmos_device.ps1
2024-02-21 10:55:41 +08:00

51 lines
2.1 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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