Add WinUtil action logging

This commit is contained in:
Chris Titus
2026-07-01 19:48:43 -05:00
parent 7a720bc5a6
commit 2ff8df7d45
19 changed files with 158 additions and 6 deletions

View File

@@ -9,8 +9,12 @@ function Install-WinUtilProgramChoco {
)
if ($Action -eq 'Install') {
Start-Process -FilePath choco -ArgumentList "install $Programs -y" -NoNewWindow -Wait
$arguments = "install $Programs -y"
} else {
Start-Process -FilePath choco -ArgumentList "uninstall $Programs -y" -NoNewWindow -Wait
$arguments = "uninstall $Programs -y"
}
Write-WinUtilLog -Component "Package" -Message "$Action choco package(s): $($Programs -join ', ')"
$process = Start-Process -FilePath choco -ArgumentList $arguments -NoNewWindow -Wait -PassThru
Write-WinUtilLog -Component "Package" -Message "$Action choco package(s) completed: $($Programs -join ', ') (exit code: $($process.ExitCode))"
}

View File

@@ -20,9 +20,13 @@ Function Install-WinUtilProgramWinget {
}
if ($Action -eq 'Install') {
Start-Process -FilePath winget -ArgumentList @("install", "--id", $program, "--accept-package-agreements", "--accept-source-agreements", "--source", $source, "--silent") -NoNewWindow -Wait
$arguments = @("install", "--id", $program, "--accept-package-agreements", "--accept-source-agreements", "--source", $source, "--silent")
} else {
Start-Process -FilePath winget -ArgumentList @("uninstall", "--id", $program, "--source", $source, "--silent") -NoNewWindow -Wait
$arguments = @("uninstall", "--id", $program, "--source", $source, "--silent")
}
Write-WinUtilLog -Component "Package" -Message "$Action winget package: $program (source: $source)"
$process = Start-Process -FilePath winget -ArgumentList $arguments -NoNewWindow -Wait -PassThru
Write-WinUtilLog -Component "Package" -Message "$Action winget package completed: $program (exit code: $($process.ExitCode))"
}
}

View File

@@ -1,16 +1,22 @@
function Invoke-WinUtilFeatureInstall ($CheckBox) {
Write-WinUtilLog -Component "Feature" -Message "Applying feature action: $CheckBox"
if ($sync.configs.feature.$CheckBox.feature) {
foreach ($feature in $sync.configs.feature.$CheckBox.feature) {
Write-Host "Installing $feature"
Write-WinUtilLog -Component "Feature" -Message "Enabling Windows optional feature: $feature"
Enable-WindowsOptionalFeature -Online -FeatureName $feature -All -NoRestart -ErrorAction Stop
Write-WinUtilLog -Component "Feature" -Message "Enabled Windows optional feature: $feature"
}
}
if ($sync.configs.feature.$CheckBox.InvokeScript) {
foreach ($script in $sync.configs.feature.$CheckBox.InvokeScript) {
Write-Host "Running Script for $CheckBox"
Write-WinUtilLog -Component "Feature" -Message "Running feature script for: $CheckBox"
Invoke-Command -ScriptBlock ([scriptblock]::Create($script)) -ErrorAction Stop
Write-WinUtilLog -Component "Feature" -Message "Completed feature script for: $CheckBox"
}
}
Write-WinUtilLog -Component "Feature" -Message "Feature action completed: $CheckBox"
}

View File

@@ -22,23 +22,30 @@ function Invoke-WinUtilScript {
try {
Write-Host "Running Script for $Name"
Write-WinUtilLog -Component "Script" -Message "Running script for $Name"
Invoke-Command $scriptblock -ErrorAction Stop
Write-WinUtilLog -Component "Script" -Message "Completed script for $Name"
} catch [System.Management.Automation.CommandNotFoundException] {
Write-Warning "The specified command was not found."
Write-Warning $PSItem.Exception.message
Write-WinUtilLog -Level "ERROR" -Component "Script" -Message "Command not found while running script for $Name`: $($PSItem.Exception.Message)"
} catch [System.Management.Automation.RuntimeException] {
Write-Warning "A runtime exception occurred."
Write-Warning $PSItem.Exception.message
Write-WinUtilLog -Level "ERROR" -Component "Script" -Message "Runtime exception while running script for $Name`: $($PSItem.Exception.Message)"
} catch [System.Security.SecurityException] {
Write-Warning "A security exception occurred."
Write-Warning $PSItem.Exception.message
Write-WinUtilLog -Level "ERROR" -Component "Script" -Message "Security exception while running script for $Name`: $($PSItem.Exception.Message)"
} catch [System.UnauthorizedAccessException] {
Write-Warning "Access denied. You do not have permission to perform this operation."
Write-Warning $PSItem.Exception.message
Write-WinUtilLog -Level "ERROR" -Component "Script" -Message "Access denied while running script for $Name`: $($PSItem.Exception.Message)"
} catch {
# Generic catch block to handle any other type of exception
Write-Warning "Unable to run script for $Name due to unhandled exception."
Write-Warning $psitem.Exception.StackTrace
Write-WinUtilLog -Level "ERROR" -Component "Script" -Message "Unhandled exception while running script for $Name`: $($psitem.Exception.Message)"
}
}

View File

@@ -21,6 +21,9 @@ function Invoke-WinUtilTweaks {
$KeepServiceStartup = $true
)
$action = if ($undo) { "Undo" } else { "Apply" }
Write-WinUtilLog -Component "Tweaks" -Message "$action tweak: $CheckBox"
if ($undo) {
$Values = @{
Registry = "OriginalValue"
@@ -77,4 +80,5 @@ function Invoke-WinUtilTweaks {
}
}
}
Write-WinUtilLog -Component "Tweaks" -Message "$action tweak completed: $CheckBox"
}

View File

@@ -16,6 +16,8 @@ function Remove-WinUtilAPPX {
)
Write-Host "Removing $Name"
Write-WinUtilLog -Component "AppX" -Message "Removing AppX package pattern: $Name"
Get-AppxPackage $Name -AllUsers | Remove-AppxPackage -AllUsers
Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like $Name | Remove-AppxProvisionedPackage -Online
Write-WinUtilLog -Component "AppX" -Message "AppX removal completed for package pattern: $Name"
}

View File

@@ -12,22 +12,31 @@ function Set-WinUtilDNS {
#>
param($DNSProvider)
if($DNSProvider -eq "Default") {return}
if($DNSProvider -eq "Default") {
Write-WinUtilLog -Component "DNS" -Message "DNS provider is Default; no DNS changes applied."
return
}
try {
$Adapters = Get-NetAdapter | Where-Object {$_.Status -eq "Up"}
Write-Host "Ensuring DNS is set to $DNSProvider on the following interfaces:"
Write-Host $($Adapters | Out-String)
Write-WinUtilLog -Component "DNS" -Message "Setting DNS provider to $DNSProvider for $(@($Adapters).Count) active adapter(s)."
Foreach ($Adapter in $Adapters) {
if($DNSProvider -eq "DHCP") {
Write-WinUtilLog -Component "DNS" -Message "Resetting DNS to DHCP on adapter $($Adapter.Name) (ifIndex: $($Adapter.ifIndex))."
Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ResetServerAddresses
} else {
Write-WinUtilLog -Component "DNS" -Message "Setting IPv4 DNS on adapter $($Adapter.Name) (ifIndex: $($Adapter.ifIndex)) to $($sync.configs.dns.$DNSProvider.Primary), $($sync.configs.dns.$DNSProvider.Secondary)."
Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ServerAddresses ("$($sync.configs.dns.$DNSProvider.Primary)", "$($sync.configs.dns.$DNSProvider.Secondary)")
Write-WinUtilLog -Component "DNS" -Message "Setting IPv6 DNS on adapter $($Adapter.Name) (ifIndex: $($Adapter.ifIndex)) to $($sync.configs.dns.$DNSProvider.Primary6), $($sync.configs.dns.$DNSProvider.Secondary6)."
Set-DnsClientServerAddress -InterfaceIndex $Adapter.ifIndex -ServerAddresses ("$($sync.configs.dns.$DNSProvider.Primary6)", "$($sync.configs.dns.$DNSProvider.Secondary6)")
}
}
Write-WinUtilLog -Component "DNS" -Message "DNS provider change completed: $DNSProvider"
} catch {
Write-Warning "Unable to set DNS Provider due to an unhandled exception."
Write-Warning $psitem.Exception.StackTrace
Write-WinUtilLog -Level "ERROR" -Component "DNS" -Message "Unable to set DNS provider $DNSProvider`: $($psitem.Exception.Message)"
}
}

View File

@@ -32,25 +32,32 @@ function Set-WinUtilRegistry {
If (!(Test-Path $Path)) {
Write-Host "$Path was not found. Creating..."
Write-WinUtilLog -Component "Registry" -Message "Creating registry path: $Path"
New-Item -Path $Path -Force -ErrorAction Stop | Out-Null
}
if ($Value -ne "<RemoveEntry>") {
Write-Host "Set $Path\$Name to $Value"
Write-WinUtilLog -Component "Registry" -Message "Setting $Path\$Name ($Type) to $Value"
Set-ItemProperty -Path $Path -Name $Name -Type $Type -Value $Value -Force -ErrorAction Stop | Out-Null
}
else{
Write-Host "Remove $Path\$Name"
Write-WinUtilLog -Component "Registry" -Message "Removing $Path\$Name"
Remove-ItemProperty -Path $Path -Name $Name -Force -ErrorAction Stop | Out-Null
}
} catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception."
Write-WinUtilLog -Level "ERROR" -Component "Registry" -Message "Security exception while changing $Path\$Name to $Value`: $($psitem.Exception.Message)"
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
Write-WinUtilLog -Level "ERROR" -Component "Registry" -Message "Registry item not found while changing $Path\$Name`: $($psitem.Exception.Message)"
} catch [System.UnauthorizedAccessException] {
Write-Warning $psitem.Exception.Message
Write-WinUtilLog -Level "ERROR" -Component "Registry" -Message "Unauthorized while changing $Path\$Name`: $($psitem.Exception.Message)"
} catch {
Write-Warning "Unable to set $Name due to unhandled exception."
Write-Warning $psitem.Exception.StackTrace
Write-WinUtilLog -Level "ERROR" -Component "Registry" -Message "Unhandled exception while changing $Path\$Name`: $($psitem.Exception.Message)"
}
}

View File

@@ -20,6 +20,7 @@ Function Set-WinUtilService {
)
try {
Write-Host "Setting Service $Name to $StartupType"
Write-WinUtilLog -Component "Service" -Message "Setting service $Name startup type to $StartupType"
# Check if the service exists
$service = Get-Service -Name $Name -ErrorAction Stop
@@ -30,11 +31,14 @@ Function Set-WinUtilService {
} else {
$service | Set-Service -StartupType $StartupType -ErrorAction Stop
}
Write-WinUtilLog -Component "Service" -Message "Service $Name startup type set to $StartupType"
} catch [System.ServiceProcess.ServiceNotFoundException] {
Write-Warning "Service $Name was not found."
Write-WinUtilLog -Level "WARN" -Component "Service" -Message "Service $Name was not found."
} catch {
Write-Warning "Unable to set $Name due to unhandled exception."
Write-Warning $_.Exception.Message
Write-WinUtilLog -Level "ERROR" -Component "Service" -Message "Unable to set service $Name to $StartupType`: $($_.Exception.Message)"
}
}

View File

@@ -0,0 +1,56 @@
function Write-WinUtilLog {
<#
.SYNOPSIS
Writes a timestamped WinUtil log entry directly to the active session log file.
.PARAMETER Message
The message to write.
.PARAMETER Level
The severity level for the log entry.
.PARAMETER Component
The WinUtil component producing the log entry.
#>
param (
[Parameter(Mandatory = $true)]
[string]$Message,
[ValidateSet("INFO", "WARN", "ERROR", "DEBUG")]
[string]$Level = "INFO",
[string]$Component = "WinUtil"
)
try {
$logPath = $null
if ($null -ne $sync -and $sync.ContainsKey("logPath")) {
$logPath = $sync.logPath
}
if ([string]::IsNullOrWhiteSpace($logPath) -and $null -ne $sync -and $sync.ContainsKey("winutildir")) {
$logPath = Join-Path $sync.winutildir "winutil.log"
}
if ([string]::IsNullOrWhiteSpace($logPath) -and -not [string]::IsNullOrWhiteSpace($env:LocalAppData)) {
$logPath = Join-Path (Join-Path $env:LocalAppData "winutil") "winutil.log"
}
if ([string]::IsNullOrWhiteSpace($logPath)) {
return
}
$logDirectory = Split-Path -Path $logPath -Parent
if (-not (Test-Path $logDirectory)) {
New-Item -Path $logDirectory -ItemType Directory -Force | Out-Null
}
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
$line = "[$timestamp] [$Level] [$Component] $Message"
Add-Content -Path $logPath -Value $line -Encoding UTF8
} catch {
Write-Warning "Unable to write WinUtil log entry: $($_.Exception.Message)"
}
}

View File

@@ -11,26 +11,32 @@ function Invoke-WPFAppxRemoval {
param($selected, $apps)
$sync.ProcessRunning = $true
Write-WinUtilLog -Component "AppX" -Message "Starting AppX removal for $(@($selected).Count) selected package(s)."
foreach ($key in $selected) {
if ($key -eq "WPFAppxMicrosoft_XboxGamingOverlay") {
# Making sure Game Bar isn't running
Write-WinUtilLog -Component "AppX" -Message "Stopping GameBarFTServer before removing Xbox Gaming Overlay."
Stop-Process -Name GameBarFTServer
# This stops annoying ms-gamebar popup when launching games.
Write-WinUtilLog -Component "AppX" -Message "Disabling Game DVR capture before removing Xbox Gaming Overlay."
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR -Name AppCaptureEnabled -Value 0
}
if ($key -eq "WPFAppxMicrosoft_WindowsNotepad") {
# i hope your having fun reading this
Write-WinUtilLog -Component "AppX" -Message "Stopping dllhost before removing Notepad."
Stop-Process -Name dllhost
}
Write-Host "Removing $($apps[$key].Content)"
Write-WinUtilLog -Component "AppX" -Message "Removing $($apps[$key].Content) ($($apps[$key].PackageId))."
Get-AppxPackage -Name $apps[$key].PackageId -AllUsers | Remove-AppxPackage -AllUsers
if ($key -eq "WPFAppxMSTeams") {
# Uninstalls Microsoft Teams Meeting Add-in for Microsoft Office
Write-WinUtilLog -Component "AppX" -Message "Uninstalling Microsoft Teams meeting add-in package."
Get-Package -Name "Microsoft Teams*" -ErrorAction SilentlyContinue | Uninstall-Package -Force
}
}
@@ -38,6 +44,7 @@ function Invoke-WPFAppxRemoval {
Write-Host "================================="
Write-Host "-- AppX Removal Finished ---"
Write-Host "================================="
Write-WinUtilLog -Component "AppX" -Message "AppX removal finished."
$sync.ProcessRunning = $false
}

View File

@@ -20,6 +20,7 @@ function Invoke-WPFInstall {
}
$ManagerPreference = $sync.preferences.packagemanager
Write-WinUtilLog -Component "Install" -Message "Install requested for $(@($PackagesToInstall).Count) selected package(s) using preference: $ManagerPreference"
$handle = Invoke-WPFRunspace -ParameterList @(("PackagesToInstall", $PackagesToInstall),("ManagerPreference", $ManagerPreference)) -ScriptBlock {
param($PackagesToInstall, $ManagerPreference)
@@ -28,6 +29,7 @@ function Invoke-WPFInstall {
$packagesWinget = $packagesSorted[[PackageManagers]::Winget]
$packagesChoco = $packagesSorted[[PackageManagers]::Choco]
Write-WinUtilLog -Component "Install" -Message "Install package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)"
try {
$sync.ProcessRunning = $true
@@ -44,11 +46,13 @@ function Invoke-WPFInstall {
Write-Host "==========================================="
Write-Host "-- Installs have finished ---"
Write-Host "==========================================="
Write-WinUtilLog -Component "Install" -Message "Install workflow completed."
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }
} catch {
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
Write-WinUtilLog -Level "ERROR" -Component "Install" -Message "Install workflow failed: $($_.Exception.Message)"
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" -overlay "warning" }
}
$sync.ProcessRunning = $False

View File

@@ -31,6 +31,7 @@ function Invoke-WPFUnInstall {
if($confirm -eq "No") {return}
$ManagerPreference = $sync.preferences.packagemanager
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall requested for $(@($PackagesToUninstall).Count) selected package(s) using preference: $ManagerPreference"
Invoke-WPFRunspace -ParameterList @(("PackagesToUninstall", $PackagesToUninstall),("ManagerPreference", $ManagerPreference)) -ScriptBlock {
param($PackagesToUninstall, $ManagerPreference)
@@ -38,6 +39,7 @@ function Invoke-WPFUnInstall {
$packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToUninstall -Preference $ManagerPreference
$packagesWinget = $packagesSorted[[PackageManagers]::Winget]
$packagesChoco = $packagesSorted[[PackageManagers]::Choco]
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)"
try {
$sync.ProcessRunning = $true
@@ -58,11 +60,13 @@ function Invoke-WPFUnInstall {
Write-Host "==========================================="
Write-Host "-- Uninstalls have finished ---"
Write-Host "==========================================="
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall workflow completed."
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }
} catch {
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
Write-WinUtilLog -Level "ERROR" -Component "Uninstall" -Message "Uninstall workflow failed: $($_.Exception.Message)"
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" -overlay "warning" }
}
$sync.ProcessRunning = $False

View File

@@ -6,8 +6,10 @@ function Invoke-WPFUpdatesdefault {
#>
$ErrorActionPreference = 'SilentlyContinue'
Write-WinUtilLog -Component "Updates" -Message "Resetting Windows Update settings to default."
Write-Host "Removing Windows Update policy settings..." -ForegroundColor Green
Write-WinUtilLog -Component "Updates" -Message "Removing Windows Update policy registry paths."
Remove-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Recurse -Force
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization" -Recurse -Force
@@ -17,24 +19,31 @@ function Invoke-WPFUpdatesdefault {
Remove-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Recurse -Force
Write-Host "Showing Windows Updates in settings..."
Write-WinUtilLog -Component "Updates" -Message "Showing Windows Update settings page."
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name SettingsPageVisibility
Write-Host "Reenabling Windows Update Services..." -ForegroundColor Green
Write-WinUtilLog -Component "Updates" -Message "Restoring Windows Update service startup types."
Write-Host "Restored BITS to Manual."
Write-WinUtilLog -Component "Updates" -Message "Restoring BITS service to Manual."
Set-Service -Name BITS -StartupType Manual
Write-Host "Restored wuauserv to Manual."
Write-WinUtilLog -Component "Updates" -Message "Restoring wuauserv service to Manual."
Set-Service -Name wuauserv -StartupType Manual
Write-Host "Restored UsoSvc to Automatic."
Write-WinUtilLog -Component "Updates" -Message "Starting UsoSvc service and restoring startup type to Automatic."
Start-Service -Name UsoSvc
Set-Service -Name UsoSvc -StartupType Automatic
Write-Host "Restored WaaSMedicSvc to Manual."
Write-WinUtilLog -Component "Updates" -Message "Restoring WaaSMedicSvc service to Manual."
Set-Service -Name WaaSMedicSvc -StartupType Manual
Write-Host "Enabling update related scheduled tasks..." -ForegroundColor Green
Write-WinUtilLog -Component "Updates" -Message "Enabling update related scheduled tasks."
$Tasks =
'\Microsoft\Windows\InstallService\*',
@@ -49,6 +58,7 @@ function Invoke-WPFUpdatesdefault {
}
Write-Host "Windows Local Policies Reset to Default."
Write-WinUtilLog -Component "Updates" -Message "Resetting local security policy to defaults with secedit."
secedit /configure /cfg "$Env:SystemRoot\inf\defltbase.inf" /db defltbase.sdb
Write-Host "===================================================" -ForegroundColor Green
@@ -56,4 +66,5 @@ function Invoke-WPFUpdatesdefault {
Write-Host "===================================================" -ForegroundColor Green
Write-Host "Note: You must restart your system in order for all changes to take effect." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Windows Update default workflow completed. Restart required."
}

View File

@@ -9,8 +9,10 @@ function Invoke-WPFUpdatesdisable {
#>
$ErrorActionPreference = 'SilentlyContinue'
Write-WinUtilLog -Component "Updates" -Message "Disabling Windows Update settings."
Write-Host "Configuring registry settings..." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Configuring Windows Update registry policy values for disable mode."
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoUpdate" -Type DWord -Value 1
@@ -20,22 +22,28 @@ function Invoke-WPFUpdatesdisable {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" -Name "DODownloadMode" -Type DWord -Value 0
Write-Host "Hiding Windows Updates from settings..."
Write-WinUtilLog -Component "Updates" -Message "Hiding Windows Update settings page."
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name SettingsPageVisibility -Value hide:windowsupdate
Write-Host "Disabled BITS Service."
Write-WinUtilLog -Component "Updates" -Message "Disabling BITS service."
Set-Service -Name BITS -StartupType Disabled
Write-Host "Disabled wuauserv Service."
Write-WinUtilLog -Component "Updates" -Message "Disabling wuauserv service."
Set-Service -Name wuauserv -StartupType Disabled
Write-Host "Disabled UsoSvc Service."
Write-WinUtilLog -Component "Updates" -Message "Stopping and disabling UsoSvc service."
Stop-Service -Name UsoSvc -Force
Set-Service -Name UsoSvc -StartupType Disabled
Remove-Item "C:\Windows\SoftwareDistribution\*" -Recurse -Force
Write-Host "Cleared SoftwareDistribution folder."
Write-WinUtilLog -Component "Updates" -Message "Cleared SoftwareDistribution folder."
Write-Host "Disabling update related scheduled tasks..." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Disabling update related scheduled tasks."
$Tasks =
'\Microsoft\Windows\InstallService\*',
@@ -54,4 +62,5 @@ function Invoke-WPFUpdatesdisable {
Write-Host "=================================" -ForegroundColor Green
Write-Host "Note: You must restart your system in order for all changes to take effect." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Windows Update disable workflow completed. Restart required."
}

View File

@@ -14,6 +14,8 @@ function Invoke-WPFUpdatessecurity {
#>
Write-Host "Disabling driver offering through Windows Update..."
Write-WinUtilLog -Component "Updates" -Message "Applying recommended Windows Update settings."
Write-WinUtilLog -Component "Updates" -Message "Disabling driver offering through Windows Update."
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" -Name "PreventDeviceMetadataFromNetwork" -Type DWord -Value 1
@@ -28,6 +30,7 @@ function Invoke-WPFUpdatessecurity {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Name "ExcludeWUDriversInQualityUpdate" -Type DWord -Value 1
Write-Host "Setting cumulative updates back by 1 year and security updates by 4 days..."
Write-WinUtilLog -Component "Updates" -Message "Deferring feature updates by 365 days and quality updates by 4 days."
New-Item -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Force
@@ -36,6 +39,7 @@ function Invoke-WPFUpdatessecurity {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "DeferQualityUpdatesPeriodInDays" -Type DWord -Value 4
Write-Host "Disabling Windows Update automatic restart..."
Write-WinUtilLog -Component "Updates" -Message "Disabling Windows Update automatic restart while users are logged in."
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoRebootWithLoggedOnUsers" -Type DWord -Value 1
@@ -44,4 +48,5 @@ function Invoke-WPFUpdatessecurity {
Write-Host "================================="
Write-Host "-- Updates Set to Recommended ---"
Write-Host "================================="
Write-WinUtilLog -Component "Updates" -Message "Recommended Windows Update settings workflow completed."
}

View File

@@ -22,6 +22,7 @@ function Invoke-WPFtweaksbutton {
$tweaksToRun = @($Tweaks | Where-Object { $_ -ne $restorePointTweak })
$totalSteps = [Math]::Max($Tweaks.Count, 1)
$completedSteps = 0
Write-WinUtilLog -Component "Tweaks" -Message "Tweaks requested: $(@($Tweaks).Count) selected tweak(s), DNS provider: $dnsProvider"
if ($tweaks.count -eq 0 -and $dnsProvider -eq "Default") {
$msg = "Please check the tweaks you wish to perform."
@@ -39,6 +40,7 @@ function Invoke-WPFtweaksbutton {
}
Set-WinUtilProgressBar -Label "Creating restore point" -Percent 0
Write-WinUtilLog -Component "Tweaks" -Message "Creating restore point before applying selected tweaks."
Invoke-WinUtilTweaks $restorePointTweak
$completedSteps = 1
@@ -49,6 +51,7 @@ function Invoke-WPFtweaksbutton {
Write-Host "================================="
Write-Host "-- Tweaks are Finished ---"
Write-Host "================================="
Write-WinUtilLog -Component "Tweaks" -Message "Tweaks workflow completed after restore point."
return
}
}
@@ -82,5 +85,6 @@ function Invoke-WPFtweaksbutton {
Write-Host "================================="
Write-Host "-- Tweaks are Finished ---"
Write-Host "================================="
Write-WinUtilLog -Component "Tweaks" -Message "Tweaks workflow completed."
}
}

View File

@@ -24,6 +24,7 @@ function Invoke-WPFundoall {
param($tweaks)
$sync.ProcessRunning = $true
Write-WinUtilLog -Component "Tweaks" -Message "Undo tweaks requested: $(@($tweaks).Count) selected tweak(s)."
if ($tweaks.count -eq 1) {
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" }
} else {
@@ -43,6 +44,7 @@ function Invoke-WPFundoall {
Write-Host "=================================="
Write-Host "--- Undo Tweaks are Finished ---"
Write-Host "=================================="
Write-WinUtilLog -Component "Tweaks" -Message "Undo tweaks workflow completed."
}
}

View File

@@ -81,10 +81,13 @@ $dateTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
# Set the path for the winutil directory
$winutildir = "$env:LocalAppData\winutil"
New-Item $winutildir -ItemType Directory -Force | Out-Null
$sync.winutildir = $winutildir
$sync.logPath = "$winutildir\winutil.log"
$logdir = "$winutildir\logs"
New-Item $logdir -ItemType Directory -Force | Out-Null
Start-Transcript -Path "$logdir\winutil_$dateTime.log" -Append -NoClobber | Out-Null
$sync.transcriptPath = "$logdir\winutil_$dateTime.log"
Start-Transcript -Path $sync.transcriptPath -Append -NoClobber | Out-Null
# Set PowerShell window title
$Host.UI.RawUI.WindowTitle = "WinUtil (Admin)"