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
69 lines (55 loc) · 2.47 KB
/
irm.ps1
File metadata and controls
69 lines (55 loc) · 2.47 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
$ProgressPreference = "SilentlyContinue"
$apiUrl = "https://api.github.com/repos/flick9000/winscript/releases/latest"
$tempFile = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), "winscript-portable.exe")
$Logo = @"
__ __ _ ____ _ _
\ \ / /(_) _ __ / ___| ___ _ __ (_) _ __ | |_
\ \ /\ / / | || '_ \ \___ \ / __|| '__|| || '_ \ | __|
\ V V / | || | | | ___) || (__ | | | || |_) || |_
\_/\_/ |_||_| |_||____/ \___||_| |_|| .__/ \__|
|_|
"@
try {
Clear-Host
# Ascii Art
Write-Host $Logo
# Check if the script is running as admin
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "This script requires administrator privileges."`n"Please run the terminal as an administrator." -ForegroundColor Red; exit }
# Remove old file if it exists
if (Test-Path $tempFile) {
Remove-Item -Path $tempFile -Force -ErrorAction SilentlyContinue
Write-Host "Removed old temporary file." -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 & run the file
Write-Host "Downloading from GitHub..." -ForegroundColor Green
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempFile
Write-Host "Starting WinScript..." -ForegroundColor Green
Start-Process -FilePath $tempFile -Wait
}
# Clean up
if (Test-Path $tempFile) {
Remove-Item -Path $tempFile -Force
Write-Host ""
Write-Host "Thanks for using WinScript!" -ForegroundColor Green
Write-Host ""
}
}
catch {
Write-Host "Error: $_" -ForegroundColor Red
Write-Host "Failed to download or run WinScript." -ForegroundColor Red
}