forked from flick9000/winscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirm.ps1
More file actions
49 lines (41 loc) · 1.73 KB
/
irm.ps1
File metadata and controls
49 lines (41 loc) · 1.73 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
48
49
# Downloads the latest version, runs it, and cleans up afterward
$apiUrl = "https://api.github.com/repos/flick9000/winscript/releases/latest"
$tempFile = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), "winscript-portable.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 portable exe
$downloadUrl = ($releaseInfo.assets | Where-Object { $_.name -eq "winscript-portable.exe" }).browser_download_url
if (-not $downloadUrl) {
throw "Could not find winscript-portable.exe in the latest release"
}
if (Test-Path $tempFile) {
Write-Host "WinScript 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 WinScript..." -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 WinScript." -ForegroundColor Red
}