# 探索するディレクトリのパスを環境変数から取得 $directoryPath = "$env:LOCALAPPDATA\BraveSoftware\Brave-Browser\Application" # 探索するファイル名 $targetFileName = "brave_.exe" $sourceFileName = "brave.exe" # ディレクトリが存在するか確認 if (-Not (Test-Path -Path $directoryPath)) { Write-Output "Brave is not installed on this computer." exit } # 管理者特権が必要か確認 if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Output "Administrator privileges are required to run this script." Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs exit } # ユーザーに確認プロンプトを表示 $confirmation = Read-Host "This script will modify Brave browser files. Do you want to continue? (Y/N)" if ($confirmation -ne "Y") { Write-Output "Operation cancelled by the user." exit } # ディレクトリ内を再帰的に探索し、brave_.exeを削除 Get-ChildItem -Path $directoryPath -Recurse -Filter $targetFileName | ForEach-Object { Remove-Item -Path $_.FullName -Force } # brave.exeを探索し、brave_.exeとしてコピー Get-ChildItem -Path $directoryPath -Recurse -Filter $sourceFileName | ForEach-Object { $sourcePath = $_.FullName $destinationPath = Join-Path -Path (Split-Path -Path $sourcePath -Parent) -ChildPath $targetFileName Copy-Item -Path $sourcePath -Destination $destinationPath -Force } Write-Output "Processing completed."