Error handling + logging
This commit is contained in:
48
install.ps1
48
install.ps1
@@ -16,7 +16,14 @@ else {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Setze das default Log Level
|
## Setze das default Log Level
|
||||||
|
Set-LoggingDefaultLevel -Level 'WARNING'
|
||||||
|
Add-LoggingTarget -Name Console
|
||||||
|
Add-LoggingTarget -Name File -Configuration @{Path = '~/.winconfig/run.log'}
|
||||||
|
|
||||||
|
|
||||||
|
Write-Log -Level ($Level | Get-Random) -Message 'Message n. {0}' -Arguments $i
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -57,22 +64,45 @@ do {
|
|||||||
$selection = Read-Host "Bitte Aufgabe auswählen"
|
$selection = Read-Host "Bitte Aufgabe auswählen"
|
||||||
switch ($selection) {
|
switch ($selection) {
|
||||||
'1' {
|
'1' {
|
||||||
foreach ($utility in $toRemove) {
|
foreach ($utility in $toRemove) {
|
||||||
winget uninstall --id $utility
|
Write-Log -Level 'INFO' -Message 'Versuche Paket {0} zu deinstallieren' -Arguments $utility
|
||||||
|
Try {
|
||||||
|
winget uninstall --id $utility
|
||||||
|
Write-Log -Level 'INFO' -Message 'Paket {0} erfolgreich deinstalliert.' -Arguments $utility
|
||||||
|
}
|
||||||
|
Catch {
|
||||||
|
Write-Log -Level 'WARN' -Message 'Paket {0} konnte nicht deinstalliert werden.' -Arguments $utility
|
||||||
|
Write-Log -Level 'WARN' -Message '$_.Exception.Message' -Arguments $utility
|
||||||
|
Write-Host "Paket $utility konnte nicht deinstalliert werden. " -ForegroundColor red
|
||||||
|
}
|
||||||
}
|
}
|
||||||
remove-item ~\Desktop* -include *.lnk
|
|
||||||
} '2' {
|
} '2' {
|
||||||
# Winget config reinrödeln
|
# Winget config installieren
|
||||||
Remove-Item "~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json"
|
if (-not(Test-Path -Path '~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json' -PathType leaf)){
|
||||||
New-Item -Path "~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json" -ItemType SymbolicLink -Value "~/.winconfig/configs/winget/settings.json"
|
New-Item -Path "~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json" -ItemType SymbolicLink -Value "~/.winconfig/configs/winget/settings.json"
|
||||||
# Krempeln deinstallieren
|
}
|
||||||
|
else {
|
||||||
|
Remove-Item "~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json"
|
||||||
|
New-Item -Path "~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json" -ItemType SymbolicLink -Value "~/.winconfig/configs/winget/settings.json"
|
||||||
|
}
|
||||||
|
# Crap deinstallieren
|
||||||
foreach ($utility in $toInstall) {
|
foreach ($utility in $toInstall) {
|
||||||
$ergebnis = winget list --id $utility
|
$ergebnis = winget list --id $utility
|
||||||
|
Write-Log -Level 'INFO' -Message 'Versuche Paket {0} zu deinstallieren' -Arguments $utility
|
||||||
if ($ergebnis -eq "Es wurde kein installiertes Paket gefunden, das den Eingabekriterien entspricht.") {
|
if ($ergebnis -eq "Es wurde kein installiertes Paket gefunden, das den Eingabekriterien entspricht.") {
|
||||||
winget install -e --id $utility --silent
|
Try {
|
||||||
|
winget install -e --id $utility --silent
|
||||||
|
Write-Log -Level 'INFO' -Message 'Paket {0} erfolgreich installiert.' -Arguments $utility
|
||||||
|
}
|
||||||
|
Catch {
|
||||||
|
Write-Log -Level 'ERROR' -Message 'Paket {0} konnte nicht installiert werden.' -Arguments $utility
|
||||||
|
Write-Log -Level 'ERROR' -Message '$_.Exception.Message' -Arguments $utility
|
||||||
|
Write-Host "Paket $utility konnte nicht installiert werden. " -ForegroundColor Red
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Host "Programm $utility bereits installiert"
|
Write-Host "Programm $utility bereits installiert" -ForegroundColor Green
|
||||||
|
Write-Log -Level 'INFO' -Message 'Paket {0} erfolgreich installiert.' -Arguments $utility
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} '3' {
|
} '3' {
|
||||||
|
|||||||
Reference in New Issue
Block a user