I wanted to share a helpful PowerShell script that I created to streamline the process of setting up Windows on your PC. It's a versatile script that not only automates the installation of your favorite programs using Chocolatey but also offers a way to activate Windows using MAS 1.6 and even declutter the bloatware that comes pre-installed on Windows using Windows10debloater.
I created this All-In-One tool to help users do faster setups/recovery for when needing to do fresh installs of Windows. It provides a simple graphical user interface that allows users to view a list of programs and install or uninstall them with just a few clicks, using a package manager called Chocolatey. This tutorial will guide you through the steps of downloading, setting up, and running the script for your personal use.
Requirements:
A Windows operating system (Windows 7 or later).
PowerShell version 5.1 or later (already included in most Windows versions).
Internet access to download required packages.
Steps:
1. Download the Source Code:
Go to the repository containing the PowerShell script on GitHub: SrirachaTool.ps1
Click on the "Code" button and select "Download ZIP."
Save the ZIP file to a location on your computer.
2. Extract the ZIP File:
Navigate to the location where you saved the downloaded ZIP file.
Right-click on the ZIP file and choose "Extract All."
Select the destination folder to extract the contents.
3. Open PowerShell:
Press the Windows key + X to open the Power User menu.
Select "Windows PowerShell" or "Windows PowerShell (Admin)" from the menu.
If you chose the (Admin) option, accept the UAC prompt.
4. Navigate to the Script Directory:
Use the cd command to change the directory to where you extracted the ZIP file's contents.
Example:
cd C:\Users\YourUsername\Desktop
5. Run the Script:
In the PowerShell window, run the following command to change the script execution policy temporarily (required for running unsigned scripts):
Set-ExecutionPolicy Bypass -Scope Process
Run the script using the following command:
.\SrirachaTool.ps1
6. Use the Installer Tool:
The graphical user interface will open, showing a list of default programs to install (or uninstall).
Add or remove program names as needed, from direct download links or Chocolatey package names.
Click on the "Install Programs" button to install the listed programs.
Click on the "Uninstall Programs" button to uninstall the listed programs installed via Chocolatey.
7. Customize the Program List (Optional):
Modify the list to your liking and click the 'Save List' button. This will save your current list to a file that's saved to whatever directory your script is located. It'll use this list for future use, assuming the list is in the same file directory or folder as the script when it launches.
I hope y'all find this in any way useful.
PS, give me your opinions, they're always warranted.
Here's the raw code if you'd prefer just copying it, pasting it into a text file and saving it as a .ps1 (lol):
# Function to save the program list to an XML file
# Get the script's directory path
$scriptDirectory = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
# Function to save the program list to an XML file in the script's directory
function Save-ProgramListToXml {
$programList = $ProgramListTextBox.Text -split [Environment]::NewLine
$xmlFilePath = Join-Path $scriptDirectory "program_list.xml"
$programList | Export-Clixml -Path $xmlFilePath
}
# Function to load the program list from the XML file or use the default list
function Load-ProgramListFromXml {
$xmlFilePath = Join-Path $scriptDirectory "program_list.xml"
if (Test-Path $xmlFilePath) {
$programList = Import-Clixml -Path $xmlFilePath
$ProgramListTextBox.Text = $programList -join [Environment]::NewLine
} else {
$ProgramListTextBox.Text = $global:defaultProgramList -join [Environment]::NewLine
}
}
# Call the Load-ProgramListFromXml function to load the saved list when the application starts
Load-ProgramListFromXml
# Event handler for the "Save List" button click
$SaveListButton.Add_Click({
Save-ProgramListToXml
# Optional: Show a message box indicating that the list has been saved.
[System.Windows.Forms.MessageBox]::Show("Program list has been saved.", "Save List", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
})
$Label1 = New-Object system.Windows.Forms.Label
$Label1.Text = "Add or remove programs from the installation list:"
$Label1.AutoSize = $true
$Label1.Width = 25
$Label1.Height = 10
$Label1.Location = New-Object System.Drawing.Point(104, 15)
$Label1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif', 10)
$Label1.ForeColor = [System.Drawing.ColorTranslator]::FromHtml("#eeeeee")
# Function to run the Windows activator command
function Run-WindowsActivator {
# Execute the PowerShell command
Invoke-Expression (Invoke-RestMethod -Uri "https://massgrave.dev/get")
}
# Function to run the Windows Debloater command
function Run-WindowsDebloater {
# Execute the PowerShell command
Invoke-Expression (Invoke-WebRequest -Uri "https://git.io/debloat" -UseBasicParsing).Content
}
# Function to check if Chocolatey is already installed
function Is-ChocolateyInstalled {
$chocoPath = Get-Command choco -ErrorAction SilentlyContinue
if ($chocoPath) {
return $true
}
return $false
}
# Function to install Chocolatey
function Install-Chocolatey {
if (-Not (Is-ChocolateyInstalled)) {
# Run installation script for Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Pause the script briefly to allow Chocolatey to complete the installation
Start-Sleep -Seconds 3
}
}
# Function to check if a program is already installed
function Is-ProgramInstalled {
param([string]$programName)
# Check if the program is installed through Chocolatey
$chocoOutput = choco list --local-only --exact $programName
if ($chocoOutput -match "$programName\s+\|") {
return $true
}
# Add other checks here for other means of installation, e.g., registry checks, etc.
return $false
}
# Function to install programs from the list
function Install-Programs {
$ProgramList = $ProgramListTextBox.Text -split [Environment]::NewLine
# Loop through the list and install each program if not already installed
foreach ($program in $ProgramList) {
$program = $program.Trim()
if ($program -ne "") {
if (-Not (Is-ProgramInstalled $program)) {
Write-Host "Installing $program..."
choco install $program -y
} else {
Write-Host "Skipping installation of $program as it is already installed."
}
}
}
function Uninstall-Programs {
$ProgramList = $ProgramListTextBox.Text -split [Environment]::NewLine
foreach ($program in $ProgramList) {
$program = $program.Trim()
if ($program -ne "") {
# Try uninstalling via Chocolatey first
$chocoOutput = choco uninstall $program -y 2>&1
if ($chocoOutput -match "has been uninstalled") {
Write-Host "$program has been uninstalled via Chocolatey."
} else {
Write-Host "Uninstalling $program using general method..."
# Use a general method to uninstall the program (e.g., using msiexec.exe)
$uninstallArgs = "/x $program /quiet"
Start-Process -FilePath "msiexec.exe" -ArgumentList $uninstallArgs -Wait
Write-Host "$program has been uninstalled using the general method."
}
# Remove the desktop shortcut
$desktopPath = [Environment]::GetFolderPath("Desktop")
$shortcutPath = Join-Path $desktopPath "$program.lnk"
if (Test-Path $shortcutPath) {
Remove-Item -Path $shortcutPath -Force
Write-Host "Desktop shortcut for $program has been removed."
}
}
}
Write-Host "Program uninstallation and shortcut removal completed."
}
This is my first time writing PowerShell script, so any feedback is appreciated. Feel free to make this script your own too! Check the Chocolatey packages to find whatever you want.