$ScriptTitle = "Cleanup Script" $WebhookURL = "https://n8n.questcomputers.be/webhook-test/8fde21e2-937f-4142-b983-6e1606e29335" # Remote scripts $ScriptCreateRestorePoint = "https://git.questcomputers.be/quest-scripts/scripts/raw/branch/main/create_restorepoint.ps1" $ScriptGetComputerInfo = "https://git.questcomputers.be/quest-scripts/scripts/raw/branch/main/pc_information.ps1" $ScriptGetInstalledAV = "https://git.questcomputers.be/quest-scripts/scripts/raw/branch/main/installed_av.ps1" $ScriptRunBleachBit = "https://git.questcomputers.be/quest-scripts/scripts/raw/branch/main/bleachbit.ps1" # Check if C:\Quest exists... $LogDirectory = "C:\Quest" if (-not (Test-Path $LogDirectory)) { New-Item -Path $LogDirectory -ItemType Directory -Force | Out-Null } # Download icon $iconUrl = "https://git.questcomputers.be/quest-scripts/scripts/raw/branch/main/assets/logo.ico" $iconPath = "$env:TEMP\icon.ico" Invoke-WebRequest -Uri $iconUrl -OutFile $iconPath -UseBasicParsing # Form Add-Type -AssemblyName System.Windows.Forms $form = New-Object System.Windows.Forms.Form $form.Text = $ScriptTitle $form.Size = New-Object System.Drawing.Size(320, 160) $form.StartPosition = "CenterScreen" $form.Topmost = $true $form.KeyPreview = $true $form.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($iconPath) # Form label $lbl = New-Object System.Windows.Forms.Label $lbl.Location = New-Object System.Drawing.Point(15, 20) $lbl.Size = New-Object System.Drawing.Size(280, 20) $lbl.Text = "Enter Ticket Number:" $form.Controls.Add($lbl) # Form textbox $txt = New-Object System.Windows.Forms.TextBox $txt.Location = New-Object System.Drawing.Point(15, 50) $txt.Size = New-Object System.Drawing.Size(280, 25) $form.Controls.Add($txt) # Form OK button $btnOK = New-Object System.Windows.Forms.Button $btnOK.Location = New-Object System.Drawing.Point(115, 90) $btnOK.Size = New-Object System.Drawing.Size(80, 28) $btnOK.Text = "OK" $btnOK.DialogResult = [System.Windows.Forms.DialogResult]::OK $form.Controls.Add($btnOK) # Form Cancel button $btnCancel = New-Object System.Windows.Forms.Button $btnCancel.Location = New-Object System.Drawing.Point(205, 90) $btnCancel.Size = New-Object System.Drawing.Size(80, 28) $btnCancel.Text = "Cancel" $btnCancel.DialogResult = [System.Windows.Forms.DialogResult]::Cancel $form.Controls.Add($btnCancel) # Wire up Enter/Esc $form.AcceptButton = $btnOK # Enter → OK $form.CancelButton = $btnCancel # Esc → Cancel # Show the dialog $form.Add_Shown({ $this.Activate() $txt.Focus() }) $result = $form.ShowDialog() # Handle the user’s choice if ($result -eq [System.Windows.Forms.DialogResult]::OK) { $ticket = $txt.Text.Trim() if ([string]::IsNullOrWhiteSpace($ticket)) { Write-Host "Empty ticket - aborting." exit } # Generate the restore point name # Format: QUEST-CLEANUP--<6_RANDOM>- $randomChars = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 6 | ForEach-Object {[char]$_}) $dateStr = Get-Date -Format "yyyy-MM-dd" # Set the $Name variable for the external script to use $Name = "QUEST-CLEANUP-$ticket-$randomChars-$dateStr" # Run scripts $CreateRestorePoint = irm $ScriptCreateRestorePoint | iex $GetComputerInfo = irm $ScriptGetComputerInfo | iex $GetInstalledAV = irm $ScriptGetInstalledAV | iex $RunBleachBit = irm $ScriptRunBleachBit | iex # Webhook try { $payload = @{ ticket = $ticket CreateRestorePoint = $CreateRestorePoint | ConvertFrom-Json GetComputerInfo = $GetComputerInfo | ConvertFrom-Json GetInstalledAV = $GetInstalledAV | ConvertFrom-Json RunBleachBit = $RunBleachBit | ConvertFrom-Json } | ConvertTo-Json -Compress $response = Invoke-RestMethod -Uri $WebhookURL -Method Post ` -Body $payload ` -ContentType "application/json" ` -ErrorAction Stop Write-Host "Ticket $ticket sent successfully." Write-Host "Webhook response:`n$($response | ConvertTo-Json -Compress)" } catch { Write-Error "Failed to send ticket: $_" } }