PowerShell/Scripts/install-basic-apps.ps1

51 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.
2023-05-01 19:32:25 +02:00
Apps from 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()
2023-05-01 19:32:25 +02:00
Write-Host "⏳ (1/32) Loading Data/basic-apps.csv... " -noNewline
2022-08-21 11:04:59 +02:00
$Table = Import-CSV "$PSScriptRoot/../Data/basic-apps.csv"
$NumEntries = $Table.count
2023-05-05 12:44:30 +02:00
Write-Host "$NumEntries apps"
2023-05-01 19:32:25 +02:00
Write-Host "⏳ (2/32) About to install or upgrade: " -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
}
""
2023-05-01 19:32:25 +02:00
"Press <Control> <C> to abort, otherwise the installation will start in 15 seconds..."
Start-Sleep -seconds 15
2022-08-21 11:04:59 +02:00
2023-05-01 19:32:25 +02:00
[int]$Step = 3
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
2023-05-01 19:32:25 +02:00
Write-Host " "
Write-Host "⏳ ($Step/$($NumEntries + 2)) Installing $Category '$AppName'..."
2022-08-21 11:04:59 +02:00
& winget install --id $AppID --accept-package-agreements --accept-source-agreements
2023-05-01 19:32:25 +02:00
if ($lastExitCode -ne "0") { $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
2023-05-05 12:44:30 +02:00
"✔️ installed $Installed of $NumEntries applications in $Elapsed sec"
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
}