# PowerShell Interactive Script Menu # Generated on: 2026-10-06 06:48:42 function Show-PrivateScriptSubMenu { param( [Parameter(Mandatory=$true)] [array]$Scripts, [Parameter(Mandatory=$true)] [string]$ApiBaseUrl, [Parameter(Mandatory=$true)] [string]$Username, [Parameter(Mandatory=$true)] [string]$Pin ) Write-Host "DEBUG (SubMenu): Received Username: $Username" -ForegroundColor DarkYellow Write-Host "DEBUG (SubMenu): Received PIN (hidden): $Pin" -ForegroundColor DarkYellow do { Clear-Host Write-Host "========================================" -ForegroundColor Blue Write-Host " Your Accessible Scripts " -ForegroundColor Blue Write-Host "========================================" -ForegroundColor Blue Write-Host "" $currentOptionIndex = 1 if ($Scripts.Count -eq 0) { Write-Host "No scripts available for your access." -ForegroundColor Yellow } else { foreach ($script in $Scripts) { $privacyTag = if ($script.is_private -eq 2) { " (Private)" } else { "" } Write-Host "[$currentOptionIndex] $($script.name)$($privacyTag)" -ForegroundColor Cyan Write-Host " Description: $($script.description | ForEach-Object { $_ -replace '\r?\n', ' ' })" -ForegroundColor DarkGray Write-Host " Uploaded by: $($script.uploaded_by_username)" -ForegroundColor DarkGray $script | Add-Member -NotePropertyName 'menu_index' -NotePropertyValue $currentOptionIndex -Force $currentOptionIndex++ } } Write-Host "" Write-Host "[B] Back to Main Menu" -ForegroundColor Red Write-Host "----------------------------------------" -ForegroundColor Gray Write-Host "" $selection = Read-Host "Enter your selection (number or B)" if ($selection -eq 'b' -or $selection -eq 'B') { break } if ($selection -as [int]) { $selectedInt = [int]$selection $selectedScript = $Scripts | Where-Object { $_.menu_index -eq $selectedInt } | Select-Object -First 1 if ($selectedScript) { Write-Host "" Write-Host "You selected: $($selectedScript.name)" -ForegroundColor Green Write-Host "Attempting to retrieve and execute..." -ForegroundColor Yellow $scriptId = $selectedScript.id $fetchUrl = $ApiBaseUrl + "/?script=" + $scriptId + "&username=" + [uri]::EscapeDataString($Username) + "&pin=" + [uri]::EscapeDataString($Pin) try { $scriptContent = Invoke-RestMethod -Uri $fetchUrl if ([string]::IsNullOrEmpty($scriptContent) -or ($scriptContent.Trim() -match '^(Access Denied|Script not found|An internal server error occurred|A database error occurred).*')) { Write-Error "Failed to retrieve script content or access denied: $scriptContent" } else { Write-Host "Executing $($selectedScript.name)..." -ForegroundColor Green Invoke-Expression $scriptContent Write-Host "" Write-Host "Script execution complete for $($selectedScript.name)." -ForegroundColor Green } } catch { Write-Error ("An error occurred while fetching or executing the script: " + $_.Exception.Message) Write-Host "Ensure you have proper network access and permissions." -ForegroundColor Red } Write-Host "" Read-Host "Press Enter to return to menu..." } else { Write-Host "Error: Could not find script for selection $selectedInt." -ForegroundColor Red Start-Sleep -Seconds 1 } } else { Write-Host "Invalid input. Please enter a number or 'B'." -ForegroundColor Red Start-Sleep -Seconds 1 } } while ($true) } function Show-ScriptSelectionMenu { param( [Parameter(Mandatory=$true)] [array]$PublicScripts, [Parameter(Mandatory=$true)] [string]$ApiBaseUrl ) do { Clear-Host Write-Host "========================================" -ForegroundColor Green Write-Host " PowerShell Script Menu " -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "" $currentOptionIndex = 1 if ($PublicScripts.Count -eq 0) { Write-Host "No public scripts currently available." -ForegroundColor Yellow } else { Write-Host "Public Scripts:" -ForegroundColor Yellow foreach ($script in $PublicScripts) { Write-Host "[$currentOptionIndex] $($script.name)" -ForegroundColor Cyan Write-Host " Description: $($script.description | ForEach-Object { $_ -replace '\r?\n', ' ' })" -ForegroundColor DarkGray Write-Host " Uploaded by: $($script.uploaded_by_username)" -ForegroundColor DarkGray $script | Add-Member -NotePropertyName 'menu_index' -NotePropertyValue $currentOptionIndex -Force $currentOptionIndex++ } Write-Host "" } # Add the 'Private Scripts' option $privateOptionIndex = $currentOptionIndex Write-Host "[$privateOptionIndex] Private Scripts (Requires Authentication)" -ForegroundColor Magenta Write-Host "" Write-Host "[Q] Quit" -ForegroundColor Red Write-Host "----------------------------------------" -ForegroundColor Gray Write-Host "" $selection = Read-Host "Enter your selection (number or Q)" if ($selection -eq 'q' -or $selection -eq 'Q') { Write-Host "Exiting script menu. Goodbye!" -ForegroundColor Yellow Start-Sleep -Seconds 1 break } if ($selection -as [int]) { $selectedInt = [int]$selection if ($selectedInt -ge 1 -and $selectedInt -lt $privateOptionIndex) { $selectedScript = $PublicScripts | Where-Object { $_.menu_index -eq $selectedInt } | Select-Object -First 1 if ($selectedScript) { Write-Host "" Write-Host "You selected: $($selectedScript.name)" -ForegroundColor Green Write-Host "Attempting to retrieve and execute..." -ForegroundColor Yellow $scriptId = $selectedScript.id $fetchUrl = $ApiBaseUrl + "/?script=" + $scriptId try { $scriptContent = Invoke-RestMethod -Uri $fetchUrl if ([string]::IsNullOrEmpty($scriptContent) -or ($scriptContent.Trim() -match '^(Access Denied|Script not found|An internal server error occurred|A database error occurred).*')) { Write-Error "Failed to retrieve script content or access denied: $scriptContent" } else { Write-Host "Executing $($selectedScript.name)..." -ForegroundColor Green Invoke-Expression $scriptContent Write-Host "" Write-Host "Script execution complete for $($selectedScript.name)." -ForegroundColor Green } } catch { Write-Error ("An error occurred while fetching or executing the script: " + $_.Exception.Message) Write-Host "Ensure you have proper network access and permissions." -ForegroundColor Red } Write-Host "" Read-Host "Press Enter to return to menu..." } else { Write-Host "Error: Could not find script for selection $selectedInt." -ForegroundColor Red Start-Sleep -Seconds 1 } } elseif ($selectedInt -eq $privateOptionIndex) { Clear-Host Write-Host "========================================" -ForegroundColor Blue Write-Host " Private Scripts Access " -ForegroundColor Blue Write-Host "========================================" -ForegroundColor Blue Write-Host "" $username = Read-Host "Enter your username" $securePin = Read-Host "Enter your PIN" -AsSecureString Add-Type -AssemblyName System.Security $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePin) $pin = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($BSTR) [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR) Write-Host "Authenticating..." -ForegroundColor Yellow Write-Host "DEBUG: Authenticated Username (captured): $username" -ForegroundColor DarkYellow Write-Host "DEBUG: Authenticated PIN (captured): $pin" -ForegroundColor DarkYellow $privateScriptsUrl = $ApiBaseUrl + "/?action=get_private_scripts&username=" + [uri]::EscapeDataString($username) + "&pin=" + [uri]::EscapeDataString($pin) try { $responseContent = Invoke-RestMethod -Uri $privateScriptsUrl if ($responseContent -match '^Write-Error') { Invoke-Expression $responseContent } else { Invoke-Expression $responseContent if ($PrivateScriptsForUser) { Show-PrivateScriptSubMenu -Scripts $PrivateScriptsForUser -ApiBaseUrl $ApiBaseUrl -Username $username -Pin $pin } else { Write-Host "No private scripts found or an issue occurred." -ForegroundColor Yellow Start-Sleep -Seconds 1 } } } catch { Write-Error ("An error occurred during private script authentication: " + $_.Exception.Message) Write-Host "Ensure your username and PIN are correct and network access is available." -ForegroundColor Red } Write-Host "" Read-Host "Press Enter to return to the main menu..." } else { Write-Host "Invalid selection. Please enter a valid number or 'Q'." -ForegroundColor Red Start-Sleep -Seconds 1 } } else { Write-Host "Invalid input. Please enter a number or 'Q'." -ForegroundColor Red Start-Sleep -Seconds 1 } } while ($true) } $PublicScriptsFromPHP = @( [pscustomobject]@{ id = 13; name = "Acrobat, Ninite and Office"; description = "This script installs Adobe Acrobat Reader, our Ninite Applications and Office"; uploaded_by_username = "Harry"; } [pscustomobject]@{ id = 1; name = "Hello World"; description = "This is a test script that will display `"Hello World`""; uploaded_by_username = "Harry"; } [pscustomobject]@{ id = 14; name = "HP Remove Bloatware"; description = "Removes built in HP Bloatware"; uploaded_by_username = "Harry"; } [pscustomobject]@{ id = 12; name = "LEAP Fix"; description = "LEAP Installer, Full Uninstaller or Full Reinstaller"; uploaded_by_username = "Harry"; } [pscustomobject]@{ id = 9; name = "Lorem Ipsum"; description = "Will write some lorem ipsum in PowerShell"; uploaded_by_username = "Harry"; } [pscustomobject]@{ id = 16; name = "Set DNS to Automatic"; description = "Sets all networking adapters DNS to automatic. Rolls back from Webroot DNS Protection"; uploaded_by_username = "Harry"; } ) Show-ScriptSelectionMenu -PublicScripts $PublicScriptsFromPHP -ApiBaseUrl "https://aio.mlogicit.com.au"