|
6 | 6 | NOTE: Apps from Microsoft Store are preferred (due to security and automatic updates).
|
7 | 7 | .EXAMPLE
|
8 | 8 | PS> ./install-basic-apps.ps1
|
9 |
| - ⏳ (1/37) Loading Data/basic-apps.csv... 35 apps |
10 |
| - ⏳ (2/37) These apps will be installed or upgraded: 7-Zip · Aquile Reader ... |
| 9 | + ⏳ (1) Loading data/basic-apps.csv... 37 apps listed |
| 10 | + ⏳ (2) Applications to install/upgrade: 7-Zip · Aquile Reader ... |
| 11 | + ... |
| 12 | + ✔️ Installed 37 basic apps (0 skipped) in 387 sec. |
11 | 13 | .LINK
|
12 | 14 | https://github.com/fleschutz/PowerShell
|
13 | 15 | .NOTES
|
14 | 16 | Author: Markus Fleschutz | License: CC0
|
15 | 17 | #>
|
16 | 18 |
|
17 | 19 | try {
|
18 |
| - $StopWatch = [system.diagnostics.stopwatch]::startNew() |
| 20 | + $stopWatch = [system.diagnostics.stopwatch]::startNew() |
19 | 21 |
|
20 |
| - Write-Host "⏳ (1/37) Loading Data/basic-apps.csv... " -noNewline |
21 |
| - $Table = Import-CSV "$PSScriptRoot/../data/basic-apps.csv" |
22 |
| - $NumEntries = $Table.count |
23 |
| - "$NumEntries apps" |
24 |
| - Write-Host "⏳ (2/37) These apps will be installed or upgraded: " -noNewline |
25 |
| - foreach($Row in $Table) { |
26 |
| - [string]$AppName = $Row.APPLICATION |
27 |
| - Write-Host "$AppName · " -noNewline |
| 22 | + Write-Host "⏳ (1) Loading data/basic-apps.csv... " -noNewline |
| 23 | + $table = Import-CSV "$PSScriptRoot/../data/basic-apps.csv" |
| 24 | + $numEntries = $table.count |
| 25 | + "$numEntries apps listed" |
| 26 | + Write-Host "⏳ (2) Applications to install/upgrade: " -noNewline |
| 27 | + foreach($row in $table) { |
| 28 | + [string]$appName = $row.APPLICATION |
| 29 | + Write-Host "$appName · " -noNewline |
28 | 30 | }
|
29 | 31 | ""
|
30 | 32 | ""
|
31 |
| - "Installation will start in 15 seconds... (otherwise press <Control> <C> to abort)" |
| 33 | + "The installation will start in 15 seconds or press <Control> <C> to abort..." |
32 | 34 | Start-Sleep -seconds 15
|
33 | 35 |
|
34 |
| - [int]$Step = 3 |
35 |
| - [int]$Skipped = 0 |
36 |
| - foreach($Row in $Table) { |
37 |
| - [string]$AppName = $Row.APPLICATION |
38 |
| - [string]$Category = $Row.CATEGORY |
39 |
| - [string]$AppID = $Row.APPID |
| 36 | + [int]$step = 3 |
| 37 | + [int]$numSkipped = 0 |
| 38 | + foreach($row in $table) { |
| 39 | + [string]$appName = $row.APPLICATION |
| 40 | + [string]$category = $row.CATEGORY |
| 41 | + [string]$appID = $row.APPID |
40 | 42 | Write-Host " "
|
41 |
| - Write-Host "⏳ ($Step/$($NumEntries + 2)) Installing $Category '$AppName'..." |
42 |
| - & winget install --id $AppID --accept-package-agreements --accept-source-agreements |
43 |
| - if ($lastExitCode -ne "0") { $Skipped++ } |
44 |
| - $Step++ |
| 43 | + Write-Host "⏳ ($step/$($numEntries + 2)) Installing $category '$appName'..." |
| 44 | + & winget install --id $appID --accept-package-agreements --accept-source-agreements |
| 45 | + if ($lastExitCode -ne "0") { $numSkipped++ } |
| 46 | + $step++ |
45 | 47 | }
|
46 |
| - [int]$Installed = ($NumEntries - $Skipped) |
47 |
| - [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds |
48 |
| - "✔️ Installation of $Installed basic apps ($Skipped skipped) took $Elapsed sec" |
| 48 | + [int]$numInstalled = ($numEntries - $numSkipped) |
| 49 | + [int]$elapsed = $stopWatch.Elapsed.TotalSeconds |
| 50 | + "✔️ Installed $numInstalled basic apps ($numSkipped skipped) in $elapsed sec." |
49 | 51 | exit 0 # success
|
50 | 52 | } catch {
|
51 | 53 | "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
0 commit comments