-
Notifications
You must be signed in to change notification settings - Fork 1
/
initialize.ps1
143 lines (127 loc) · 5.49 KB
/
initialize.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
###############################################################################################################
# | __ __.__ .___ #
# | / \ / \__| ____ __| _/______ _ ________ #
# Author : Jonathan Rux | \ \/\/ / |/ \ / __ |/ _ \ \/ \/ / ___/ #
# Email : [email protected] | \ /| | | \/ /_/ ( <_> ) /\___ \ #
# Version : 2.0 | \__/\ / |__|___| /\____ |\____/ \/\_//____ > #
# OS Support : Windows 10,11 x64 | \/ \/ \/ \/ #
# | Initialization Setup Script. #
# | #
###############################################################################################################
<#
.DESCRIPTION
This script initializes Windows 10/11 x64 and, then, installs initial software needed by employees at <insert company here>.
.SYNOPSIS
This script initializes Windows 10/11 x64 and, then, installs initial software needed by employees at <insert company here>.
#>
#########################
# Functions #
#########################
# 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 "$($title)`n$('='*64)`n"
}
# Function to install AppxPackage
function AAP {
param (
[string]$pkg
)
<#
.SYNOPSIS
Installs AppxPackage.
.DESCRIPTION
Installs AppxPackage.
#>
Write-Output " Installing $($pkg)..."
Add-AppxPackage -ErrorAction:SilentlyContinue $pkg
Write-Output " $($pkg) installed. Continuing...`n"
}
# Function to install prerequisites for Winget
function InstallPrereqs {
<#
.DESCRIPTION
Downloads and Installs Winget Prerequisites.
.SYNOPSIS
Downloads and Installs Winget Prerequisites.
#>
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 -title "Checking for Winget..."
if (-not (Get-Command -ErrorAction SilentlyContinue winget)) {
Write-Host " Winget not found. Installing prerequisites...`n"
InstallPrereqs
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-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 -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