-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTool.ps1
More file actions
47 lines (41 loc) · 1.76 KB
/
Copy pathTool.ps1
File metadata and controls
47 lines (41 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Downloads the latest version of ToolboxBS, runs it, and cleans up afterward
$apiUrl = "https://api.github.com/repos/BrandonSepulveda/ToolboxBS/releases/latest"
$tempFile = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), "ToolboxBS.exe")
try {
# Remove old file if it exists (may sometimes cause issues)
if (Test-Path $tempFile) {
Remove-Item -Path $tempFile -Force
Write-Host "Old temporary file removed." -ForegroundColor Green
}
# Get latest release info
$releaseInfo = Invoke-RestMethod -Uri $apiUrl -Headers @{
"Accept" = "application/vnd.github.v3+json"
"User-Agent" = "PowerShell Script"
}
# Get download URL for the exe
$downloadUrl = ($releaseInfo.assets | Where-Object { $_.name -eq "ToolboxBS.exe" }).browser_download_url
if (-not $downloadUrl) {
throw "Could not find ToolboxBS.exe in the latest release"
}
if (Test-Path $tempFile) {
Write-Host "ToolboxBS already downloaded, starting..." -ForegroundColor Green
Start-Process -FilePath $tempFile -Wait
}
else {
# Download the file
Write-Host "Downloading from GitHub..." -ForegroundColor Green
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempFile
# Run the executable
Write-Host "Starting ToolboxBS..." -ForegroundColor Green
Start-Process -FilePath $tempFile -Wait
}
# Clean up after execution
if (Test-Path $tempFile) {
Remove-Item -Path $tempFile -Force
Write-Host "Temporary file removed, done!" -ForegroundColor Green
}
}
catch {
Write-Host "Error: $_" -ForegroundColor Red
Write-Host "Failed to download or run ToolboxBS." -ForegroundColor Red
}