Logging geändert.

This commit is contained in:
2022-12-30 16:10:50 +01:00
parent 1162a7db82
commit 2ee1861d95

View File

@@ -1,27 +1,12 @@
## Fragt nach Admin Rechten. # Log starten
Start-Transcript -Path $HOME/.winconfig/run.log
## Fragt nach Admin Rechten.
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'" $arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments Start-Process powershell -Verb runAs -ArgumentList $arguments
Break Break
} }
## Prüfen ob das Loggin Modul installiert ist
if (Get-Module -ListAvailable -Name Logging) {
}
else {
Write-Host "Erster Start des Scripts erkannt." -ForegroundColor Red -BackgroundColor Yellow
Write-Host "Installiere Logging Modul" -ForegroundColor Red
Install-Module -Name Logging -Force
}
## Setze das default Log Level
Set-LoggingDefaultLevel -Level 'WARNING'
Add-LoggingTarget -Name Console
Add-LoggingTarget -Name File -Configuration @{Path = 'run.log'}
# Konfig für die prompts # Konfig für die prompts
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription] $choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
@@ -61,25 +46,21 @@ do {
switch ($selection) { switch ($selection) {
'1' { '1' {
foreach ($utility in $toRemove) { foreach ($utility in $toRemove) {
Write-Log -Level 'INFO' -Message 'Versuche Paket {0} zu deinstallieren' -Arguments $utility
Try { Try {
winget uninstall --id $utility winget uninstall --id $utility
Write-Log -Level 'INFO' -Message 'Paket {0} erfolgreich deinstalliert.' -Arguments $utility
} }
Catch { 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 Write-Host "Paket $utility konnte nicht deinstalliert werden. " -ForegroundColor red
} }
} }
} '2' { } '2' {
# Winget config installieren # Winget config installieren
if (-not(Test-Path -Path '~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json' -PathType leaf)){ 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" | Out-Null
} }
else { else {
Remove-Item "~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json" 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" New-Item -Path "~\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json" -ItemType SymbolicLink -Value "~/.winconfig/configs/winget/settings.json" | Out-Null
} }
# Crap deinstallieren # Crap deinstallieren
foreach ($utility in $toInstall) { foreach ($utility in $toInstall) {
@@ -170,3 +151,4 @@ do {
pause pause
} }
until ($selection -eq 'q') until ($selection -eq 'q')
Stop-Transcript