Tuesday, August 18, 2026

GPOZaurr

 https://github.com/EvotecIT/GPOZaurr
# Windows 10 Latest
Add-WindowsCapability -Online -Name 'Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0'
Add-WindowsCapability -Online -Name 'Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0'

Install-Module -Name GPOZaurr -AllowClobber -Force

Update-Module -Name GPOZaurr

winget all

 winget upgrade --all --silent --accept-package-agreements --accept-source-agreements

 

 

 

<#
.SYNOPSIS
    Automated Winget multi-package updater with detailed console streaming and disk logging.
.DESCRIPTION
    Enumerates available winget updates, processes each package sequentially with custom
    verbose outputs, captures standard out/err streams, and logs results under C:\Temp.
#>

[CmdletBinding()]
param()

# --- 1. Environment & Logging Setup ---
$ErrorActionPreference = 'Continue'
$LogDirectory = "C:\Temp"
$Timestamp    = Get-Date -Format "yyyyMMdd_HHmmss"
$MainLogFile  = Join-Path -Path $LogDirectory -ChildPath "Winget_Upgrade_$Timestamp.log"
$WingetLogDir = Join-Path -Path $LogDirectory -ChildPath "Winget_InstallLogs_$Timestamp"

# Ensure directories exist
if (-not (Test-Path -Path $LogDirectory)) {
    New-Item -ItemType Directory -Path $LogDirectory -Force | Out-Null
}
if (-not (Test-Path -Path $WingetLogDir)) {
    New-Item -ItemType Directory -Path $WingetLogDir -Force | Out-Null
}

function Write-Log {
    param (
        [Parameter(Mandatory = $true)]
        [string]$Message,
        [ValidateSet('INFO', 'SUCCESS', 'WARN', 'ERROR')]
        [string]$Level = 'INFO'
    )
    
    $TimeStr = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $FormattedMessage = "[$TimeStr] [$Level] $Message"
    
    # Write to master disk log
    Add-Content -Path $MainLogFile -Value $FormattedMessage
    
    # Write styled output to host
    switch ($Level) {
        'INFO'    { Write-Host $FormattedMessage -ForegroundColor Cyan }
        'SUCCESS' { Write-Host $FormattedMessage -ForegroundColor Green }
        'WARN'    { Write-Host $FormattedMessage -ForegroundColor Yellow }
        'ERROR'   { Write-Host $FormattedMessage -ForegroundColor Red }
    }
}

Write-Log "Starting automated Winget upgrade workflow..." 'INFO'
Write-Log "Master log: $MainLogFile" 'INFO'
Write-Log "Native installer logs: $WingetLogDir" 'INFO'

# --- 2. Administrative Privilege Validation ---
$IsAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $IsAdmin) {
    Write-Log "Execution context is NOT elevated. System-wide/machine installs may fail." 'WARN'
}

# --- 3. Discover Available Updates ---
Write-Log "Querying WinGet repository for available updates..." 'INFO'

$UpgradeListRaw = & winget upgrade --include-unknown --accept-source-agreements 2>&1
$UpgradeListRaw | Out-File -FilePath (Join-Path $LogDirectory "Winget_RawQuery_$Timestamp.log")

# Isolate package IDs using Winget's structured output format
$UpgradablePackages = @()
$SeparatorFound = $false

foreach ($line in $UpgradeListRaw) {
    if ($line -match '^-{4,}') {
        $SeparatorFound = $true
        continue
    }
    if ($SeparatorFound -and $line -match '\S+') {
        # Match columns: Name, Id, Version, Available, Source
        $Tokens = ($line -split '\s{2,}') | Where-Object { $_ -ne '' }
        if ($Tokens.Count -ge 4) {
            $UpgradablePackages += [PSCustomObject]@{
                Name             = $Tokens[0].Trim()
                Id               = $Tokens[1].Trim()
                InstalledVersion = $Tokens[2].Trim()
                AvailableVersion = $Tokens[3].Trim()
            }
        }
    }
}

if ($UpgradablePackages.Count -eq 0) {
    Write-Log "No packages require upgrading. System is fully patched." 'SUCCESS'
    exit 0
}

Write-Log "Discovered $($UpgradablePackages.Count) package(s) with available updates." 'INFO'

# --- 4. Sequential Package Upgrades with Telemetry ---
$SuccessCount = 0
$FailureCount = 0

foreach ($pkg in $UpgradablePackages) {
    Write-Host "`n" + ("=" * 70) -ForegroundColor DarkGray
    Write-Log "Upgrading [$($pkg.Name)] (ID: $($pkg.Id)) | Current: $($pkg.InstalledVersion) -> Target: $($pkg.AvailableVersion)" 'INFO'
    
    $SanitizedId = $pkg.Id -replace '[\\/:*?"<>|]', '_'
    $InstallerLog = Join-Path -Path $WingetLogDir -ChildPath "$($SanitizedId).log"

    # Direct native engine parameters
    $WingetArgs = @(
        "upgrade",
        "--id", "`"$($pkg.Id)`"",
        "-e",
        "--silent",
        "--accept-package-agreements",
        "--accept-source-agreements",
        "--log", "`"$InstallerLog`""
    )

    $ProcessStartInfo = New-Object System.Diagnostics.ProcessStartInfo
    $ProcessStartInfo.FileName = "winget.exe"
    $ProcessStartInfo.Arguments = $WingetArgs -join " "
    $ProcessStartInfo.RedirectStandardOutput = $true
    $ProcessStartInfo.RedirectStandardError = $true
    $ProcessStartInfo.UseShellExecute = $false
    $ProcessStartInfo.CreateNoWindow = $true

    $Process = New-Object System.Diagnostics.Process
    $Process.StartInfo = $ProcessStartInfo

    # Start and monitor process execution
    $Process.Start() | Out-Null
    
    $StdOut = $Process.StandardOutput.ReadToEnd()
    $StdErr = $Process.StandardError.ReadToEnd()
    $Process.WaitForExit()

    $ExitCode = $Process.ExitCode

    # Log command telemetry
    if ($StdOut) { Add-Content -Path $MainLogFile -Value "`n--- STDOUT [$($pkg.Id)] ---`n$StdOut" }
    if ($StdErr) { Add-Content -Path $MainLogFile -Value "`n--- STDERR [$($pkg.Id)] ---`n$StdErr" }

    # Validate results (0 = Success, -1978335189 / 0x8A15002B = No update available/already updated)
    if ($ExitCode -eq 0) {
        Write-Log "Successfully upgraded [$($pkg.Name)]" 'SUCCESS'
        $SuccessCount++
    }
    elseif ($ExitCode -eq -1978335189) {
        Write-Log "[$($pkg.Name)] is already up to date or has no applicable update." 'WARN'
    }
    else {
        Write-Log "Failed to upgrade [$($pkg.Name)]. Exit Code: $ExitCode" 'ERROR'
        Write-Log "Check package installer log: $InstallerLog" 'WARN'
        $FailureCount++
    }
}

# --- 5. Execution Summary ---
Write-Host "`n" + ("=" * 70) -ForegroundColor DarkGray
Write-Log "Upgrade session completed." 'INFO'
Write-Log "Total: $($UpgradablePackages.Count) | Succeeded: $SuccessCount | Failed: $FailureCount" $(if ($FailureCount -eq 0) { 'SUCCESS' } else { 'WARN' })
Write-Log "All logs stored under $LogDirectory" 'INFO' 

GPOZaurr

 https://github.com/EvotecIT/GPOZaurr # Windows 10 Latest Add-WindowsCapability -Online -Name 'Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0....