PowerShell/Scripts/install-basic-apps.ps1

50 lines
1.6 KiB
PowerShell
Raw Normal View History

2022-08-21 11:04:59 +02:00
<#
.SYNOPSIS
Installs basic apps
.DESCRIPTION
2023-02-19 10:51:25 +01:00
This PowerShell script installs basic Windows apps such as browser, e-mail client, etc.
Apps from the Microsoft Store are preferred (due to security and automatic updates).
2022-08-21 11:04:59 +02:00
.EXAMPLE
PS> ./install-basic-apps
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
2022-12-28 13:24:05 +01:00
"⏳ Step 1 - Loading Data/basic-apps.csv..."
2022-08-21 11:04:59 +02:00
$Table = Import-CSV "$PSScriptRoot/../Data/basic-apps.csv"
$NumEntries = $Table.count
2022-12-28 13:24:05 +01:00
Write-Host " The following $NumEntries basic apps will be installed or upgraded: " -NoNewline
2022-08-29 11:55:06 +02:00
foreach($Row in $Table) {
2023-02-19 10:51:25 +01:00
[string]$AppName = $Row.APPLICATION
2022-08-29 11:55:06 +02:00
Write-Host "$AppName, " -NoNewline
}
""
2022-12-28 13:24:05 +01:00
"Press <Control> <C> to abort, otherwise the installation will start in 10 seconds..."
2023-03-01 10:52:37 +01:00
Start-Sleep -seconds 10
2022-08-21 11:04:59 +02:00
[int]$Step = 2
2022-12-28 13:24:05 +01:00
[int]$Failed = 0
2022-08-21 11:04:59 +02:00
foreach($Row in $Table) {
2023-02-19 10:51:25 +01:00
[string]$AppName = $Row.APPLICATION
[string]$Category = $Row.CATEGORY
[string]$AppID = $Row.APPID
2022-08-21 11:04:59 +02:00
2022-12-28 13:24:05 +01:00
"⏳ ($Step/$($NumEntries + 1)) Installing $AppName ($Category)..."
2022-08-21 11:04:59 +02:00
& winget install --id $AppID --accept-package-agreements --accept-source-agreements
2022-12-28 13:24:05 +01:00
if ($lastExitCode -ne "0") { Write-Warning "'winget install' for $AppName failed"; $Failed++ }
2022-08-21 11:04:59 +02:00
$Step++
}
2022-12-28 13:24:05 +01:00
[int]$Installed = ($NumEntries - $Failed)
2022-08-21 11:04:59 +02:00
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
2022-12-28 13:24:05 +01:00
"✔️ installed $Installed basic apps in $Elapsed sec. ($Failed failed)"
2022-08-21 11:04:59 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
2023-02-19 10:51:25 +01:00
}