Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e0cc6c6
Fixing prereq downloads.
underscore-jr Jan 17, 2024
9a10133
Fixing prereq downloads.
underscore-jr Jan 17, 2024
2887d62
Fixing prereq downloads.
underscore-jr Jan 17, 2024
38ba215
Update Readme for Execution Policy Bypass
underscore-jr Jan 17, 2024
421e39e
Removed "Remove-Item" scripts
underscore-jr Jan 17, 2024
3952fc1
Changed to using Github API for latest release detection.
underscore-jr Jan 17, 2024
efc5fdb
Updated Variable Names.
underscore-jr Jan 17, 2024
a5816ff
Updated winget-cli msixbundle to use AAP, as well.
underscore-jr Jan 17, 2024
69d5ccb
Added debug to test variables
underscore-jr Jan 17, 2024
479cb07
More debug.
underscore-jr Jan 17, 2024
5982efa
Convert $latestUri into uri type by adding [uri] as prefix to variable
underscore-jr Jan 17, 2024
e17f91c
Revert to keeping default type. More debugging.
underscore-jr Jan 17, 2024
f86417e
Fix index. 2 instead of 3.
underscore-jr Jan 17, 2024
d1533f9
Debug Formatting.
underscore-jr Jan 17, 2024
bc263b7
Write-Output formatting.
underscore-jr Jan 17, 2024
615332c
AddColor to Titles
underscore-jr Jan 17, 2024
e513ae2
AddColor to Titles
underscore-jr Jan 17, 2024
215f6f2
No color for titles, will work on it some other day. D:
underscore-jr Jan 17, 2024
4e1a132
Move uri conversion to Get-LatestVersion function.
underscore-jr Jan 17, 2024
113e2f8
Change method of uri conversion.
underscore-jr Jan 17, 2024
808b981
Changed param handling and attempting another uri conversion.
underscore-jr Jan 17, 2024
2349d41
Attempting another different method of uri conversion.
underscore-jr Jan 17, 2024
1db5300
assetUrl was an array. Needed to convert the first value in the array…
underscore-jr Jan 17, 2024
aa7fa5d
Using constructor to create a new System.Uri.
underscore-jr Jan 17, 2024
b14cac5
Cast the assetUrl as a string.
underscore-jr Jan 17, 2024
c4b86a9
Testing types of variables
underscore-jr Jan 17, 2024
98a8cd4
Type of assetUrl is string. Testing without coverting assetUrl to ass…
underscore-jr Jan 17, 2024
51e50bd
Remove return of value from Get-LatestGitHubRelease and attempt Iwr w…
underscore-jr Jan 17, 2024
740b178
Added comments and fixed formatting.
underscore-jr Jan 17, 2024
56af116
Fixed winget import command to point to $appsJson instead of $Apps.
underscore-jr Jan 17, 2024
5330e97
More formatting changes for readability.
underscore-jr Jan 17, 2024
22b347c
Added example.png for preview on how it looks when ran.
underscore-jr Jan 17, 2024
781d8c2
Added end output when completed import of applications from JSON
underscore-jr Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This PowerShell script initializes a Windows 10/11 x64 machine and installs initial software needed by employees at a company or for individual use. It uses the winget package manager to install applications listed in the `apps.json` file.

![image](img/example.png)

## Requirements

- Windows 10/11 x64 machine
Expand All @@ -12,16 +14,17 @@ This PowerShell script initializes a Windows 10/11 x64 machine and installs init

1. Clone this repository to your local machine.
2. Open PowerShell as Administrator and navigate to the directory where the script is located.
3. Run the script by entering the following command: `.\initialize.ps1`.
3. Set Execution Policy to Bypass: `Set-ExecutionPolicy Bypass` **#Remember to never run scripts blindly.**
4. Run the script by entering the following command: `.\initialize.ps1`.

## Functionality

The script consists of the following functions:

- `AAP($pkg)`: installs AppxPackage.
- `InstallPrereqs()`: installs winget prerequisites from the `.\prereqs` directory.
- `WingetCheck()`: checks for winget; if it doesn't exist, installs prerequisites and winget.
- `InstallApps()`: installs apps from JSON list.
- `AAP`: installs AppxPackage.
- `InstallPrereqs`: installs winget prerequisites from the `.\prereqs` directory.
- `WingetCheck`: checks for winget; if it doesn't exist, installs prerequisites and winget.
- `InstallApps`: installs apps from JSON list. **#You may comment out InstallApps in the "Call Functions" section if you would only like the script to install Winget.**

The script checks whether the winget package manager is installed on the machine. If it is not installed, the script installs the prerequisites for winget and then downloads and installs winget. After installing W=winget, the script installs the applications listed in the `.\apps.json` file using winget import.

Expand Down
Binary file added img/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 71 additions & 22 deletions initialize.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# | / \ / \__| ____ __| _/______ _ ________ #
# Author : Jonathan Rux | \ \/\/ / |/ \ / __ |/ _ \ \/ \/ / ___/ #
# Email : jonathan.e.rux@underscore.com | \ /| | | \/ /_/ ( <_> ) /\___ \ #
# Version : 1.1 | \__/\ / |__|___| /\____ |\____/ \/\_//____ > #
# Version : 2.0 | \__/\ / |__|___| /\____ |\____/ \/\_//____ > #
# OS Support : Windows 10,11 x64 | \/ \/ \/ \/ #
# | Initialization Setup Script. #
# | #
Expand All @@ -20,75 +20,124 @@
# Functions #
#########################

function header($title) {

# Function to create a header for each section
function header {
param (
[string]$title
)
<#
.DESCRIPTION
Creates header for each function.
.SYNOPSIS
Creates header for each function.
#>
Write-Output "`n $title`n=============================================`n"
Write-Output "$($title)`n$('='*64)`n"
}

function AAP($pkg) {
# Function to install AppxPackage
function AAP {
param (
[string]$pkg
)
<#
.SYNOPSIS
Installs AppxPackage.
.DESCRIPTION
Installs AppxPackage.
#>
Add-AppxPackage -ErrorAction:SilentlyContinue $pkg
Write-Output " Installing $($pkg)..."
Add-AppxPackage -ErrorAction:SilentlyContinue $pkg
Write-Output " $($pkg) installed. Continuing...`n"
}

# Function to install prerequisites for Winget
function InstallPrereqs {
<#
.DESCRIPTION
Installs Winget Prerequisites from the .\prereqs directory.
Downloads and Installs Winget Prerequisites.
.SYNOPSIS
Installs Winget Prerequisites from the .\prereqs directory.
Downloads and Installs Winget Prerequisites.
#>

header("Installing Winget Prerequisites...")
AAP(".\prereqs\Microsoft.VCLibs.x64.14.00.Desktop.appx")
AAP(".\prereqs\Microsoft.UI.Xaml.2.7.appx")
header -title "Installing winget-cli Prerequisites..."
Write-Output " Downloading Microsoft.VCLibs.x64.14.00.Desktop.appx..."
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx
Write-Output " Downloading Microsoft.UI.Xaml.2.7.x64.appx...`n"
Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx -OutFile Microsoft.UI.Xaml.2.7.x64.appx
AAP -pkg "Microsoft.VCLibs.x64.14.00.Desktop.appx"
AAP -pkg "Microsoft.UI.Xaml.2.7.x64.appx"
}

# Function to get the latest version of Winget from GitHub
function Get-LatestGitHubRelease {
<#
.DESCRIPTION
Checks Github API for latest version of Winget.
.SYNOPSIS
Checks Github API for latest version of Winget.
#>
param (
[int]$assetIndex
)

header -title "Checking GitHub API for the latest version of winget-cli..."

try {
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
$latestVersion = $response.tag_name
Write-Output " Latest version:`t$($latestVersion)`n"
$assetUrl = $response.assets[$assetIndex].browser_download_url
Invoke-WebRequest -Uri $assetUrl -OutFile Microsoft.DesktopAppInstaller.msixbundle
} catch {
Write-Host " Error: $_"
}
}


# Function to check for Winget; if not found, install prerequisites and Winget
function WingetCheck {
<#
.SYNOPSIS
Check for Winget; If doesn't exist, install prerequisites and winget.
.DESCRIPTION
Check for Winget; If doesn't exist, install prerequisites and winget.
#>
header("Checking for Winget...")
header -title "Checking for Winget..."
if (-not (Get-Command -ErrorAction SilentlyContinue winget)) {
$ProgressPreference = 'Silent'
Write-Host " Winget not found. Installing prerequisites...`n"
InstallPrereqs
Write-Output "Downloading and installing winget..."
$url = "https://github.com/microsoft/winget-cli/releases/download/v1.4.10173/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
Invoke-WebRequest -Uri $url -OutFile "Microsoft.DesktopAppInstaller.msixbundle"
Start-Process -FilePath "Microsoft.DesktopAppInstaller.msixbundle" -ArgumentList "/silent", "/install" -Wait
Remove-Item "Microsoft.DesktopAppInstaller.msixbundle"
Write-Output "Refreshing Environment Variables..."
Write-Host " Downloading the latest winget-cli...`n"
Get-LatestGitHubRelease -assetIndex 2
Write-Output " Installing winget-cli..."
AAP -pkg "Microsoft.DesktopAppInstaller.msixbundle"
Write-Output " Refreshing Environment Variables...`n"
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}
Write-Output "Winget is installed. Continuing..."
Write-Output " Winget-cli is installed. Continuing...`n"
}

# Function to install applications from a JSON list
function InstallApps {
<#
.SYNOPSIS
Install apps from json list.
.DESCRIPTION
Install apps from json list.
#>
header("Installing Applications...")
$Apps = ".\apps.json"
winget import -i $Apps --accept-package-agreements --accept-source-agreements
header -title "Installing Applications..."
$appsJson = ".\apps.json"
Write-Output " Installing applications from $($appsJson)..."
winget import -i $appsJson --accept-package-agreements --accept-source-agreements
Write-Output " Complete install of applications from $($appsJson)... Exiting..."
}

#########################
# Call Functions #
#########################

# Check for Winget and install if not found
WingetCheck

# Install applications
InstallApps
Binary file removed prereqs/Microsoft.UI.Xaml.2.7.appx
Binary file not shown.
Binary file removed prereqs/Microsoft.VCLibs.x64.14.00.Desktop.appx
Binary file not shown.