Public/Invoke-WingetRussianRoulette.ps1

"function Invoke-WingetRussianRoulette {\n <#\n .SYNOPSIS\n Picks a random package from winget and installs it.\n .DESCRIPTION\n Extremely chaotic feature. Pulls a random package from the Winget repository and attempts to install it.\n .PARAMETER Confirm\n Prompt for confirmation before installing a random package.\n .PARAMETER YOLO\n Skip all confirmations and just do it.\n #>\n [CmdletBinding()]\n param(\n [Parameter()]\n [switch]$YOLO\n )\n\n Write-Host \"Spinning the Winget cylinder...\" -ForegroundColor Red\n\n # Search for random letter to get a large pool\n $letters = \"abcdefghijklmnopqrstuvwxyz\".ToCharArray()\n $randomLetter = $letters | Get-Random\n\n $results = winget search $randomLetter --accept-source-agreements 2>&1\n $packages = @()\n\n foreach ($line in $results) {\n if ($line -match '\\s+([A-Za-z][A-Za-z0-9]*\\.[A-Za-z0-9][A-Za-z0-9\\.\\-_]*)\\s+') {\n $packages += $matches[1].Trim()\n }\n }\n\n if ($packages.Count -eq 0) {\n Write-Host \"The chamber was empty. You survived.\" -ForegroundColor Green\n return\n }\n\n $target = $packages | Get-Random\n Write-Host \"CLICK! The hammer strikes on: \" -NoNewline -ForegroundColor Yellow\n Write-Host $target -ForegroundColor Red\n\n if (-not $YOLO) {\n $confirm = Read-Host \"Are you sure you want to install $target? (y/N)\"\n if ($confirm -notmatch \"^y\") {\n Write-Host \"You pulled away from the table. The package was not installed.\" -ForegroundColor DarkGray\n return\n }\n }\n\n Write-Host \"Installing $target...\" -ForegroundColor Cyan\n winget install --id $target --accept-package-agreements --accept-source-agreements\n \n if ($LASTEXITCODE -eq 0) {\n Write-Host \"Installation successful! Enjoy your random software.\" -ForegroundColor Green\n } else {\n Write-Host \"Installation failed. The software gods spared your system.\" <truncated 35 bytes>