From 19ac53040c0e4f4dc71b3a550e16b84a42ed0ae0 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:39:22 +0100 Subject: [PATCH 1/6] Improve indentation consistency Thanks @og-mrk for creating the preprocessor for WinUtil, and for letting other projects use it --- Compile.ps1 | 61 ++++++++ tools/Invoke-Preprocessing.ps1 | 159 +++++++++++++++++++++ updgui.ps1 | 252 ++++++++++++++++----------------- 3 files changed, 346 insertions(+), 126 deletions(-) create mode 100644 Compile.ps1 create mode 100644 tools/Invoke-Preprocessing.ps1 diff --git a/Compile.ps1 b/Compile.ps1 new file mode 100644 index 0000000..c613f2c --- /dev/null +++ b/Compile.ps1 @@ -0,0 +1,61 @@ +# This is a heavily modified compilation script for the Preinstallation Environment Helper, originally from the Windows Utility (WinUtil) +# +# Original license (affects both this script and the pre-processor): +# +# MIT License +# +# Copyright (c) 2022 CT Tech Group LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +$workingdir = $PSScriptRoot + +Push-Location +Set-Location $workingdir + +# Variable to sync between runspaces +$sync = [Hashtable]::Synchronized(@{}) +$sync.PSScriptRoot = $workingdir +$sync.configs = @{} + +function Update-Progress { + param ( + [Parameter(Mandatory, position=0)] + [string]$StatusMessage, + + [Parameter(Mandatory, position=1)] + [ValidateRange(0,100)] + [int]$Percent, + + [Parameter(position=2)] + [string]$Activity = "Compiling" + ) + + Write-Progress -Activity $Activity -Status $StatusMessage -PercentComplete $Percent +} + +Update-Progress "Pre-req: Running Preprocessor..." 0 + +# Dot source the 'Invoke-Preprocessing' Function from 'tools/Invoke-Preprocessing.ps1' Script +$preprocessingFilePath = ".\tools\Invoke-Preprocessing.ps1" +. $preprocessingFilePath + +$excludedFiles = @('*.png', '*.exe', 'Compile.ps1') +$msg = "Pre-req: Code Formatting" +Invoke-Preprocessing -WorkingDir "$workingdir" -ExcludedFiles $excludedFiles -ProgressStatusMessage $msg -ThrowExceptionOnEmptyFilesList \ No newline at end of file diff --git a/tools/Invoke-Preprocessing.ps1 b/tools/Invoke-Preprocessing.ps1 new file mode 100644 index 0000000..a8f65b0 --- /dev/null +++ b/tools/Invoke-Preprocessing.ps1 @@ -0,0 +1,159 @@ +function Invoke-Preprocessing { + <# + .SYNOPSIS + A function that does Code Formatting using RegEx, useful when trying to force specific coding standard(s) to a project. + + .PARAMETER ThrowExceptionOnEmptyFilesList + A switch which'll throw an exception upon not finding any files inside the provided 'WorkingDir'. + + .PARAMETER SkipExcludedFilesValidation + A switch to stop file path validation on 'ExcludedFiles' list. + + .PARAMETER ExcludedFiles + A list of file paths which're *relative to* 'WorkingDir' Folder, every item in the list can be pointing to File (doesn't end with '\') or Directory (ends with '\') or None-Existing File/Directory. + By default, it checks if everyitem exists, and throws an exception if one or more are not found (None-Existing), if you want to skip this validation, please consider providing the '-SkipExcludedFilesValidation' switch to skip this check. + + .PARAMETER WorkingDir + The folder to search inside recursively for files which're going to be Preprocessed (Code Formatted), unless they're found in 'ExcludedFiles' List. + Note: The path should be absolute, NOT relative. + + .PARAMETER ProgressStatusMessage + The status message used when displaying the progress bar, which's done through PowerShell 'Write-Progress' Cmdlet. + This's a Required Parameter, as the information displayed to terminal is useful when running this function, + which might take less than 1 sec to minutes depending on project's scale & hardware performance. + + .PARAMETER ProgressActivity + The activity message used when displaying the progress bar, which's done through PowerShell 'Write-Progress' Cmdlet, + This's an Optional Parameter, default value is 'Preprocessing', used in combination with 'ProgressStatusMessage' Parameter Value. + + .EXAMPLE + Invoke-Preprocessing -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing" + + Calls 'Invoke-Preprocessing' function using Named Paramters, with 'WorkingDir' (Mandatory Parameter) which's used as the base folder when searching for files recursively (using 'Get-ChildItem'), other two paramters are, in order from right to left, the Optional 'ExcludeFiles', which can be a path to a file, folder, or pattern-matched (like '*.png'), and the 'ProgressStatusMessage', which's used in Progress Bar. + + .EXAMPLE + Invoke-Preprocessing -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing" -ProgressActivity "Re-Formatting Code" + + Same as Example No. 1, but uses 'ProgressActivity' which's used in Progress Bar. + + .EXAMPLE + Invoke-Preprocessing -ThrowExceptionOnEmptyFilesList -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing" + + Same as Example No. 1, but uses '-ThrowExceptionOnEmptyFilesList', which's an optional parameter that'll make 'Invoke-Preprocessing' throw an exception when no files are found in 'WorkingDir' (not including the ExcludedFiles, of course), useful when you want to double check your parameters & you're sure there's files to process in the 'WorkingDir'. + + .EXAMPLE + Invoke-Preprocessing -Skip -WorkingDir "DRIVE:\Path\To\Folder\" -ExcludedFiles @('file.txt', '.\.git\', '*.png') -ProgressStatusMessage "Doing Preprocessing" + + Same as Example No. 1, but uses '-SkipExcludedFilesValidation', which'll skip the validation step for 'ExcludedFiles' list. This can be useful when 'ExcludedFiles' list is generated from another function, or from unreliable source (you can't guarantee every item in list is a valid path), but you want to silently continue through the function. + #> + + param ( + [Parameter(position=0)] + [switch]$SkipExcludedFilesValidation, + + [Parameter(position=1)] + [switch]$ThrowExceptionOnEmptyFilesList, + + [Parameter(Mandatory, position=2)] + [ValidateScript({[System.IO.Path]::IsPathRooted($_)})] + [string]$WorkingDir, + + [Parameter(position=3)] + [string[]]$ExcludedFiles, + + [Parameter(Mandatory, position=4)] + [string]$ProgressStatusMessage, + + [Parameter(position=5)] + [string]$ProgressActivity = "Preprocessing" + ) + + if (-NOT (Test-Path -PathType Container -Path "$WorkingDir")) { + throw "[Invoke-Preprocessing] Invalid Paramter Value for 'WorkingDir', passed value: '$WorkingDir'. Either the path is a File or Non-Existing/Invlid, please double check your code." + } + + $count = $ExcludedFiles.Count + + # Make sure there's a * at the end of folders in ExcludedFiles list + for ($i = 0; $i -lt $count; $i++) { + $excludedFile = $ExcludedFiles[$i] + $isFolder = ($excludedFile) -match '\\$' + if ($isFolder) { $ExcludedFiles[$i] = $excludedFile + '*' } + } + + # Get Files List + [System.Collections.ArrayList]$files = Get-ChildItem $WorkingDir -Recurse -Exclude $ExcludedFiles -File -Force + $numOfFiles = $files.Count + + # Only keep the 'FullName' Property for every entry in the list + for ($i = 0; $i -lt $numOfFiles; $i++) { + $file = $files[$i] + $files[$i] = $file.FullName + } + + # If a file(s) are found in Exclude List, + # Remove the file from files list. + for ($j = 0; $j -lt $excludedFiles.Count; $j++) { + # Prepare some variables + $excluded = $excludedFiles[$j] + $pathToFind = ($excluded) -replace ('^\.\\', '') + $pathToFind = $WorkingDir + '\' + $pathToFind + $index = -1 # reset index on every iteration + + # Handle paths with wildcards in a different implementation + $matches = ($pathToFind) -match '^.*?\*' + + if ($matches) { + $filesToCheck = Get-ChildItem -Recurse -Path "$pathToFind" -File -Force + if ($filesToCheck) { + for ($k = 0; $k -lt $filesToCheck.Count; $k++) { + $fileToCheck = $filesToCheck[$k] + $index = $files.IndexOf("$fileToCheck") + if ($index -ge 0) { $files.RemoveAt($index) } + } + } + } else { + $index = $files.IndexOf("$pathToFind") + if ($index -ge 0) { $files.RemoveAt($index) } + } + } + + # Make sure 'numOfFiles' is synced with the actual Number of Files found in '$files' + # This's done because previous may or may not edit the files list, so we should update it + $numOfFiles = $files.Count + + if ($numOfFiles -eq 0) { + if ($ThrowExceptionOnEmptyFilesList) { + throw "[Invoke-Preprocessing] Found 0 Files to Preprocess inside 'WorkingDir' Directory and '-ThrowExceptionOnEmptyFilesList' Switch is provided, value of 'WorkingDir': '$WorkingDir'." + } else { + return # Do an early return, there's nothing else to do + } + } + + for ($i = 0; $i -lt 1; $i++) { + $files[0] = "$((Get-Location).Path)\updgui.ps1" + $files[1] = "$((Get-Location).Path)\updgui.designer.ps1" + $files[2] = "$((Get-Location).Path)\updgui.resources.ps1" + $files[3] = "$((Get-Location).Path)\aboutform.ps1" + $files[4] = "$((Get-Location).Path)\aboutform.designer.ps1" + $files[5] = "$((Get-Location).Path)\aboutform.resources.ps1" + $fullFileName = $files[$i] + (Get-Content "$fullFileName").TrimEnd() ` + -replace ('\t', ' ') ` + -replace ('\)\s*\{', ') {') ` + -replace ('(?if|for|foreach)\s*(?\([.*?]\))\s*\{', '${keyword} ${condition} {') ` + -replace ('\}\s*elseif\s*(?\([.*?]\))\s*\{', '} elseif ${condition} {') ` + -replace ('\}\s*else\s*\{', '} else {') ` + -replace ('Try\s*\{', 'try {') ` + -replace ('Catch\s*\{', 'catch {') ` + -replace ('\}\s*Catch', '} catch') ` + -replace ('\}\s*Catch\s*(?(\[.*?\]\s*(\,)?\s*)+)\s*\{', '} catch ${exceptions} {') ` + -replace ('\}\s*Catch\s*(?\[.*?\])\s*\{', '} catch ${exceptions} {') ` + -replace ('(?\[[^$0-9]+\])\s*(?\$.*?)', '${parameter_type}${str_after_type}') ` + | Set-Content "$fullFileName" + + Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished $i out of $numOfFiles" -PercentComplete (($i/$numOfFiles)*100) + } + + Write-Progress -Activity $ProgressActivity -Status "$ProgressStatusMessage - Finished Task Successfully" -Completed +} diff --git a/updgui.ps1 b/updgui.ps1 index 4eb02eb..1f50a30 100644 --- a/updgui.ps1 +++ b/updgui.ps1 @@ -1,153 +1,153 @@ $Button3_Click = { - . (Join-Path $PSScriptRoot 'aboutform.designer.ps1') - $AboutForm.ShowDialog($Form1) + . (Join-Path $PSScriptRoot 'aboutform.designer.ps1') + $AboutForm.ShowDialog($Form1) } $ListView1_ItemChecked = { - if ($ListView1.CheckedItems.Count -gt 0) { - $Button2.Enabled = $true - } else { - $Button2.Enabled = $false - } + if ($ListView1.CheckedItems.Count -gt 0) { + $Button2.Enabled = $true + } else { + $Button2.Enabled = $false + } } $ListView1_SelectedIndexChanged = { - if ($ListView1.CheckedItems.Count -gt 0) { - $Button2.Enabled = $true - } else { - $Button2.Enabled = $false - } + if ($ListView1.CheckedItems.Count -gt 0) { + $Button2.Enabled = $true + } else { + $Button2.Enabled = $false + } } $Button2_Click = { - # Install selected updates - if ($ListView1.CheckedItems.Count -gt 0) { - $CheckBox1.Enabled = $false - $Label1.Visible = $true - Invoke-InfoLogging "Installing selected updates. Please wait..." - Invoke-InfoLogging "While you're waiting, why not listen to some cheerful music? https://www.youtube.com/watch?v=QHdZjxrG35U" - $checkedUpdates = $ListView1.CheckedItems - foreach ($selLVI in $checkedUpdates) { - Invoke-InfoLogging "Installing update with name: `"$($selLVI.SubItems[4].Text)`" (KB Article ID: $($selLVI.SubItems[2].Text))..." - if ($selLVI.Subitems[2].Text -ne "") { - if ($CheckBox1.Checked -eq $true) { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -Verbose - } else { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false - } - } else { - if ($CheckBox1.Checked -eq $true) { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -Verbose - } else { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false - } - } - if ($?) { - Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has been successfully installed" - $ListView1.Items.Remove($selLVI) - } else { - Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has not been installed" - Invoke-InfoLogging "Error information: $_.Exception.Message" - } - } - $Label1.Visible = $false - $CheckBox1.Enabled = $true - } else { - [System.Windows.Forms.MessageBox]::Show("Please select updates to install and try again.") - } + # Install selected updates + if ($ListView1.CheckedItems.Count -gt 0) { + $CheckBox1.Enabled = $false + $Label1.Visible = $true + Invoke-InfoLogging "Installing selected updates. Please wait..." + Invoke-InfoLogging "While you're waiting, why not listen to some cheerful music? https://www.youtube.com/watch?v=QHdZjxrG35U" + $checkedUpdates = $ListView1.CheckedItems + foreach ($selLVI in $checkedUpdates) { + Invoke-InfoLogging "Installing update with name: `"$($selLVI.SubItems[4].Text)`" (KB Article ID: $($selLVI.SubItems[2].Text))..." + if ($selLVI.Subitems[2].Text -ne "") { + if ($CheckBox1.Checked -eq $true) { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -Verbose + } else { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false + } + } else { + if ($CheckBox1.Checked -eq $true) { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -Verbose + } else { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false + } + } + if ($?) { + Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has been successfully installed" + $ListView1.Items.Remove($selLVI) + } else { + Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has not been installed" + Invoke-InfoLogging "Error information: $_.Exception.Message" + } + } + $Label1.Visible = $false + $CheckBox1.Enabled = $true + } else { + [System.Windows.Forms.MessageBox]::Show("Please select updates to install and try again.") + } } $Form1_FormClosed = { } $Form1_FormClosing = { } $Button1_Click = { - $ListView1.Items.Clear() - # Get Windows Updates - Invoke-InfoLogging "Getting Windows updates. Please wait..." - $availableUpdates = Get-WindowsUpdates - Invoke-InfoLogging "Available updates: $($availableUpdates.Count)" - if ($availableUpdates.Count -gt 0) { - Invoke-InfoLogging "Displaying updates..." - for ($i = 0; $i -lt $availableUpdates.Count; $i++) { - $ListView1.Items.Add([System.Windows.Forms.ListViewItem]::new([string[]]@( - "", - $availableUpdates[$i].ComputerName, - $availableUpdates[$i].KB, - $availableUpdates[$i].Size, - $availableUpdates[$i].Title - ))) - } - } else { - Invoke-InfoLogging "Your system is up to date." - [System.Windows.Forms.MessageBox]::Show("Your system is up to date.") - } + $ListView1.Items.Clear() + # Get Windows Updates + Invoke-InfoLogging "Getting Windows updates. Please wait..." + $availableUpdates = Get-WindowsUpdates + Invoke-InfoLogging "Available updates: $($availableUpdates.Count)" + if ($availableUpdates.Count -gt 0) { + Invoke-InfoLogging "Displaying updates..." + for ($i = 0; $i -lt $availableUpdates.Count; $i++) { + $ListView1.Items.Add([System.Windows.Forms.ListViewItem]::new([string[]]@( + "", + $availableUpdates[$i].ComputerName, + $availableUpdates[$i].KB, + $availableUpdates[$i].Size, + $availableUpdates[$i].Title + ))) + } + } else { + Invoke-InfoLogging "Your system is up to date." + [System.Windows.Forms.MessageBox]::Show("Your system is up to date.") + } } function Get-WindowsUpdates { - return Get-WindowsUpdate + return Get-WindowsUpdate } function Invoke-InfoLogging { - param ( - [Parameter(Mandatory, Position = 0)] [string] $message - ) - Write-Host "[$(Get-Date)] $message" + param ( + [Parameter(Mandatory, Position = 0)] [string]$message + ) + Write-Host "[$(Get-Date)] $message" } function Check-PSWindowsUpdate { - try { - Invoke-InfoLogging "Checking PSWindowsUpdate..." - if ((Get-Module -Name PSWindowsUpdate -ListAvailable).Count -lt 1) { - Invoke-InfoLogging "PSWindowsUpdate not detected. Installing..." - Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force - Set-PSRepository -Name PSGallery -InstallationPolicy Trusted - Install-Module PSWindowsUpdate -Force - if ((Get-Module -Name PSWindowsUpdate -ListAvailable).Count -lt 1) { throw } - } - if ((Get-Module -Name PSWindowsUpdate).Count -lt 1) { - Invoke-InfoLogging "PSWindowsUpdate not imported. Importing..." - Import-Module PSWindowsUpdate - if ((Get-Module -Name PSWindowsUpdate).Count -lt 1) { throw } - } - Invoke-InfoLogging "Either the PSWindowsUpdate module has been successfully imported or no actions had to be done in the first place. Continuing startup..." - } - catch { - Invoke-InfoLogging "Unable to check PSWindowsUpdate. Error: $($_.Exception.Message). Exiting..." - exit 1 - } + try { + Invoke-InfoLogging "Checking PSWindowsUpdate..." + if ((Get-Module -Name PSWindowsUpdate -ListAvailable).Count -lt 1) { + Invoke-InfoLogging "PSWindowsUpdate not detected. Installing..." + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + Install-Module PSWindowsUpdate -Force + if ((Get-Module -Name PSWindowsUpdate -ListAvailable).Count -lt 1) { throw } + } + if ((Get-Module -Name PSWindowsUpdate).Count -lt 1) { + Invoke-InfoLogging "PSWindowsUpdate not imported. Importing..." + Import-Module PSWindowsUpdate + if ((Get-Module -Name PSWindowsUpdate).Count -lt 1) { throw } + } + Invoke-InfoLogging "Either the PSWindowsUpdate module has been successfully imported or no actions had to be done in the first place. Continuing startup..." + } + catch { + Invoke-InfoLogging "Unable to check PSWindowsUpdate. Error: $($_.Exception.Message). Exiting..." + exit 1 + } } function Show-StartupGraphic { - # Show a cool graphic on startup - Write-Host -NoNewline "`n`n" - Write-Host " dddddddd " - Write-Host " UUUUUUUU UUUUUUUU d::::::d GGGGGGGGGGGGGUUUUUUUU UUUUUUUUIIIIIIIIII" - Write-Host " U::::::U U::::::U d::::::d GGG::::::::::::GU::::::U U::::::UI::::::::I" - Write-Host " U::::::U U::::::U d::::::d GG:::::::::::::::GU::::::U U::::::UI::::::::I" - Write-Host " UU:::::U U:::::UU d:::::d G:::::GGGGGGGG::::GUU:::::U U:::::UUII::::::II" - Write-Host " U:::::U U:::::Uppppp ppppppppp ddddddddd:::::d G:::::G GGGGGG U:::::U U:::::U I::::I " - Write-Host " U:::::D D:::::Up::::ppp:::::::::p dd::::::::::::::dG:::::G U:::::D D:::::U I::::I " - Write-Host " U:::::D D:::::Up:::::::::::::::::p d::::::::::::::::dG:::::G U:::::D D:::::U I::::I " - Write-Host " U:::::D D:::::Upp::::::ppppp::::::pd:::::::ddddd:::::dG:::::G GGGGGGGGGG U:::::D D:::::U I::::I " - Write-Host " U:::::D D:::::U p:::::p p:::::pd::::::d d:::::dG:::::G G::::::::G U:::::D D:::::U I::::I " - Write-Host " U:::::D D:::::U p:::::p p:::::pd:::::d d:::::dG:::::G GGGGG::::G U:::::D D:::::U I::::I " - Write-Host " U:::::D D:::::U p:::::p p:::::pd:::::d d:::::dG:::::G G::::G U:::::D D:::::U I::::I " - Write-Host " U::::::U U::::::U p:::::p p::::::pd:::::d d:::::d G:::::G G::::G U::::::U U::::::U I::::I " - Write-Host " U:::::::UUU:::::::U p:::::ppppp:::::::pd::::::ddddd::::::dd G:::::GGGGGGGG::::G U:::::::UUU:::::::U II::::::II" - Write-Host " UU:::::::::::::UU p::::::::::::::::p d:::::::::::::::::d GG:::::::::::::::G UU:::::::::::::UU I::::::::I" - Write-Host " UU:::::::::UU p::::::::::::::pp d:::::::::ddd::::d GGG::::::GGG:::G UU:::::::::UU I::::::::I" - Write-Host " UUUUUUUUU p::::::pppppppp ddddddddd ddddd GGGGGG GGGG UUUUUUUUU IIIIIIIIII" - Write-Host " p:::::p " - Write-Host " p:::::p " - Write-Host " p:::::::p " - Write-Host " p:::::::p " - Write-Host " p:::::::p " - Write-Host " ppppppppp " - Write-Host -NoNewline "`n`n" - Write-Host " A simple front-end for PSWindowsUpdate. " - Write-Host " Version 1.0 " - Write-Host " Programming: https://www.github.com/CodingWonders " - Write-Host " Idea: https://www.github.com/og-mrk " - Write-Host "" - Write-Host " ASCII graphic: http://patorjk.com/software/taag " - Write-Host "" + # Show a cool graphic on startup + Write-Host -NoNewline "`n`n" + Write-Host " dddddddd " + Write-Host " UUUUUUUU UUUUUUUU d::::::d GGGGGGGGGGGGGUUUUUUUU UUUUUUUUIIIIIIIIII" + Write-Host " U::::::U U::::::U d::::::d GGG::::::::::::GU::::::U U::::::UI::::::::I" + Write-Host " U::::::U U::::::U d::::::d GG:::::::::::::::GU::::::U U::::::UI::::::::I" + Write-Host " UU:::::U U:::::UU d:::::d G:::::GGGGGGGG::::GUU:::::U U:::::UUII::::::II" + Write-Host " U:::::U U:::::Uppppp ppppppppp ddddddddd:::::d G:::::G GGGGGG U:::::U U:::::U I::::I " + Write-Host " U:::::D D:::::Up::::ppp:::::::::p dd::::::::::::::dG:::::G U:::::D D:::::U I::::I " + Write-Host " U:::::D D:::::Up:::::::::::::::::p d::::::::::::::::dG:::::G U:::::D D:::::U I::::I " + Write-Host " U:::::D D:::::Upp::::::ppppp::::::pd:::::::ddddd:::::dG:::::G GGGGGGGGGG U:::::D D:::::U I::::I " + Write-Host " U:::::D D:::::U p:::::p p:::::pd::::::d d:::::dG:::::G G::::::::G U:::::D D:::::U I::::I " + Write-Host " U:::::D D:::::U p:::::p p:::::pd:::::d d:::::dG:::::G GGGGG::::G U:::::D D:::::U I::::I " + Write-Host " U:::::D D:::::U p:::::p p:::::pd:::::d d:::::dG:::::G G::::G U:::::D D:::::U I::::I " + Write-Host " U::::::U U::::::U p:::::p p::::::pd:::::d d:::::d G:::::G G::::G U::::::U U::::::U I::::I " + Write-Host " U:::::::UUU:::::::U p:::::ppppp:::::::pd::::::ddddd::::::dd G:::::GGGGGGGG::::G U:::::::UUU:::::::U II::::::II" + Write-Host " UU:::::::::::::UU p::::::::::::::::p d:::::::::::::::::d GG:::::::::::::::G UU:::::::::::::UU I::::::::I" + Write-Host " UU:::::::::UU p::::::::::::::pp d:::::::::ddd::::d GGG::::::GGG:::G UU:::::::::UU I::::::::I" + Write-Host " UUUUUUUUU p::::::pppppppp ddddddddd ddddd GGGGGG GGGG UUUUUUUUU IIIIIIIIII" + Write-Host " p:::::p " + Write-Host " p:::::p " + Write-Host " p:::::::p " + Write-Host " p:::::::p " + Write-Host " p:::::::p " + Write-Host " ppppppppp " + Write-Host -NoNewline "`n`n" + Write-Host " A simple front-end for PSWindowsUpdate. " + Write-Host " Version 1.0 " + Write-Host " Programming: https://www.github.com/CodingWonders " + Write-Host " Idea: https://www.github.com/og-mrk " + Write-Host "" + Write-Host " ASCII graphic: http://patorjk.com/software/taag " + Write-Host "" } Clear-Host @@ -162,4 +162,4 @@ Check-PSWindowsUpdate Add-Type -AssemblyName System.Windows.Forms . (Join-Path $PSScriptRoot 'updgui.designer.ps1') $Form1.ShowDialog() | Out-Null -Clear-Host \ No newline at end of file +Clear-Host From 7b07613e086c2433628c72edd0060dab97060d4d Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:45:02 +0100 Subject: [PATCH 2/6] Update version info --- aboutform.resources.ps1 | 2 +- updgui.ps1 | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/aboutform.resources.ps1 b/aboutform.resources.ps1 index dad48c5..95458a3 100644 --- a/aboutform.resources.ps1 +++ b/aboutform.resources.ps1 @@ -4,7 +4,7 @@ 'Button1.Name' = 'Button1' 'RichTextBox1.Text' = 'UpdGUI is a simple front-end written in PowerShell for the PSWindowsUpdate module. -Version: 1.0 +Version: v.Next - Programming: CodingWonders (https://www.github.com/CodingWonders) - Idea: og-mrk (https://www.github.com/og-mrk) diff --git a/updgui.ps1 b/updgui.ps1 index 1f50a30..ebe48ab 100644 --- a/updgui.ps1 +++ b/updgui.ps1 @@ -115,6 +115,7 @@ function Check-PSWindowsUpdate { } function Show-StartupGraphic { + $verConst = "v.Next" # Show a cool graphic on startup Write-Host -NoNewline "`n`n" Write-Host " dddddddd " @@ -142,7 +143,7 @@ function Show-StartupGraphic { Write-Host " ppppppppp " Write-Host -NoNewline "`n`n" Write-Host " A simple front-end for PSWindowsUpdate. " - Write-Host " Version 1.0 " + Write-Host " Version $verConst " Write-Host " Programming: https://www.github.com/CodingWonders " Write-Host " Idea: https://www.github.com/og-mrk " Write-Host "" From 6bb975d0cb9d10b23712a5d32cf671e06070e586 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:01:39 +0100 Subject: [PATCH 3/6] Skip loop if all updates are selected Attempt 1 --- updgui.ps1 | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/updgui.ps1 b/updgui.ps1 index ebe48ab..d132a2a 100644 --- a/updgui.ps1 +++ b/updgui.ps1 @@ -24,28 +24,36 @@ $Button2_Click = { Invoke-InfoLogging "Installing selected updates. Please wait..." Invoke-InfoLogging "While you're waiting, why not listen to some cheerful music? https://www.youtube.com/watch?v=QHdZjxrG35U" $checkedUpdates = $ListView1.CheckedItems - foreach ($selLVI in $checkedUpdates) { - Invoke-InfoLogging "Installing update with name: `"$($selLVI.SubItems[4].Text)`" (KB Article ID: $($selLVI.SubItems[2].Text))..." - if ($selLVI.Subitems[2].Text -ne "") { - if ($CheckBox1.Checked -eq $true) { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -Verbose + if ($ListView1.CheckedItems.Count -ge $ListView1.Items.Count) { + if ($CheckBox1.Checked -eq $true) { + Install-WindowsUpdate -Verbose + } else { + Install-WindowsUpdate + } + } else { + foreach ($selLVI in $checkedUpdates) { + Invoke-InfoLogging "Installing update with name: `"$($selLVI.SubItems[4].Text)`" (KB Article ID: $($selLVI.SubItems[2].Text))..." + if ($selLVI.Subitems[2].Text -ne "") { + if ($CheckBox1.Checked -eq $true) { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -Verbose + } else { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false + } } else { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false + if ($CheckBox1.Checked -eq $true) { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -Verbose + } else { + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false + } } - } else { - if ($CheckBox1.Checked -eq $true) { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -Verbose + if ($?) { + Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has been successfully installed" + $ListView1.Items.Remove($selLVI) } else { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false + Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has not been installed" + Invoke-InfoLogging "Error information: $_.Exception.Message" } } - if ($?) { - Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has been successfully installed" - $ListView1.Items.Remove($selLVI) - } else { - Invoke-InfoLogging "Update with name `"$($selLVI.SubItems[4].Text)`" has not been installed" - Invoke-InfoLogging "Error information: $_.Exception.Message" - } } $Label1.Visible = $false $CheckBox1.Enabled = $true From 90ee42b9fc1dd31ec6748564f95ae30a81846030 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:12:17 +0100 Subject: [PATCH 4/6] Skip confirmation --- updgui.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/updgui.ps1 b/updgui.ps1 index d132a2a..28df14f 100644 --- a/updgui.ps1 +++ b/updgui.ps1 @@ -26,9 +26,9 @@ $Button2_Click = { $checkedUpdates = $ListView1.CheckedItems if ($ListView1.CheckedItems.Count -ge $ListView1.Items.Count) { if ($CheckBox1.Checked -eq $true) { - Install-WindowsUpdate -Verbose + Install-WindowsUpdate -Verbose -Confirm:$false } else { - Install-WindowsUpdate + Install-WindowsUpdate -Confirm:$false } } else { foreach ($selLVI in $checkedUpdates) { From 3c4298a032ec9b3cf78bee570362e8a1705a0e89 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:29:10 +0100 Subject: [PATCH 5/6] Clear listview after installation --- updgui.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/updgui.ps1 b/updgui.ps1 index 28df14f..ac949e8 100644 --- a/updgui.ps1 +++ b/updgui.ps1 @@ -25,11 +25,13 @@ $Button2_Click = { Invoke-InfoLogging "While you're waiting, why not listen to some cheerful music? https://www.youtube.com/watch?v=QHdZjxrG35U" $checkedUpdates = $ListView1.CheckedItems if ($ListView1.CheckedItems.Count -ge $ListView1.Items.Count) { + Invoke-InfoLogging "Installing $($ListView1.Items.Count) update(s)..." if ($CheckBox1.Checked -eq $true) { Install-WindowsUpdate -Verbose -Confirm:$false } else { Install-WindowsUpdate -Confirm:$false } + $ListView1.Items.Clear() } else { foreach ($selLVI in $checkedUpdates) { Invoke-InfoLogging "Installing update with name: `"$($selLVI.SubItems[4].Text)`" (KB Article ID: $($selLVI.SubItems[2].Text))..." From 0b05cf072e44870fd8a59e46c027a4bfa2230259 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Sat, 15 Feb 2025 17:40:35 +0100 Subject: [PATCH 6/6] Version 1.1 Finalization - Ignore reboots - (Sort of) major redesign, adding the ability to get update history --- aboutform.resources.ps1 | 2 +- updgui.designer.ps1 | 275 ++++++++++++++++++++++++++++++++++++++-- updgui.ps1 | 43 ++++++- updgui.resources.ps1 | 30 ++++- 4 files changed, 322 insertions(+), 28 deletions(-) diff --git a/aboutform.resources.ps1 b/aboutform.resources.ps1 index 95458a3..1dc0d38 100644 --- a/aboutform.resources.ps1 +++ b/aboutform.resources.ps1 @@ -4,7 +4,7 @@ 'Button1.Name' = 'Button1' 'RichTextBox1.Text' = 'UpdGUI is a simple front-end written in PowerShell for the PSWindowsUpdate module. -Version: v.Next +Version: 1.1 - Programming: CodingWonders (https://www.github.com/CodingWonders) - Idea: og-mrk (https://www.github.com/og-mrk) diff --git a/updgui.designer.ps1 b/updgui.designer.ps1 index 6e0c3d8..5168be0 100644 --- a/updgui.designer.ps1 +++ b/updgui.designer.ps1 @@ -10,6 +10,22 @@ $Form1 = New-Object -TypeName System.Windows.Forms.Form [System.Windows.Forms.Label]$Label1 = $null [System.Windows.Forms.Button]$Button3 = $null [System.Windows.Forms.CheckBox]$CheckBox1 = $null +[System.Windows.Forms.Label]$Label2 = $null +[System.Windows.Forms.Panel]$UpdateInstallationPanel = $null +[System.Windows.Forms.Button]$Button4 = $null +[System.Windows.Forms.Button]$Button5 = $null +[System.Windows.Forms.Panel]$UpdateHistoryPanel = $null +[System.Windows.Forms.ListView]$ListView7 = $null +[System.Windows.Forms.ColumnHeader]$ColumnHeader6 = $null +[System.Windows.Forms.ColumnHeader]$ColumnHeader7 = $null +[System.Windows.Forms.ColumnHeader]$ColumnHeader8 = $null +[System.Windows.Forms.ColumnHeader]$ColumnHeader9 = $null +[System.Windows.Forms.ColumnHeader]$ColumnHeader10 = $null +[System.Windows.Forms.ListView]$ListView2 = $null +[System.Windows.Forms.ListView]$ListView3 = $null +[System.Windows.Forms.ListView]$ListView4 = $null +[System.Windows.Forms.ListView]$ListView5 = $null +[System.Windows.Forms.ListView]$ListView6 = $null function InitializeComponent { $ListView1 = (New-Object -TypeName System.Windows.Forms.ListView) @@ -23,6 +39,24 @@ $Button2 = (New-Object -TypeName System.Windows.Forms.Button) $Label1 = (New-Object -TypeName System.Windows.Forms.Label) $Button3 = (New-Object -TypeName System.Windows.Forms.Button) $CheckBox1 = (New-Object -TypeName System.Windows.Forms.CheckBox) +$Label2 = (New-Object -TypeName System.Windows.Forms.Label) +$UpdateInstallationPanel = (New-Object -TypeName System.Windows.Forms.Panel) +$Button4 = (New-Object -TypeName System.Windows.Forms.Button) +$Button5 = (New-Object -TypeName System.Windows.Forms.Button) +$UpdateHistoryPanel = (New-Object -TypeName System.Windows.Forms.Panel) +$ListView7 = (New-Object -TypeName System.Windows.Forms.ListView) +$ColumnHeader6 = (New-Object -TypeName System.Windows.Forms.ColumnHeader) +$ColumnHeader7 = (New-Object -TypeName System.Windows.Forms.ColumnHeader) +$ColumnHeader8 = (New-Object -TypeName System.Windows.Forms.ColumnHeader) +$ColumnHeader9 = (New-Object -TypeName System.Windows.Forms.ColumnHeader) +$ColumnHeader10 = (New-Object -TypeName System.Windows.Forms.ColumnHeader) +$ListView2 = (New-Object -TypeName System.Windows.Forms.ListView) +$ListView3 = (New-Object -TypeName System.Windows.Forms.ListView) +$ListView4 = (New-Object -TypeName System.Windows.Forms.ListView) +$ListView5 = (New-Object -TypeName System.Windows.Forms.ListView) +$ListView6 = (New-Object -TypeName System.Windows.Forms.ListView) +$UpdateInstallationPanel.SuspendLayout() +$UpdateHistoryPanel.SuspendLayout() $Form1.SuspendLayout() # #ListView1 @@ -32,9 +66,9 @@ $ListView1.CheckBoxes = $true $ListView1.Columns.AddRange([System.Windows.Forms.ColumnHeader[]]@($ColumnHeader5,$ColumnHeader1,$ColumnHeader2,$ColumnHeader3,$ColumnHeader4)) $ListView1.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) $ListView1.FullRowSelect = $true -$ListView1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]12,[System.Int32]12)) +$ListView1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]0,[System.Int32]0)) $ListView1.Name = [System.String]'ListView1' -$ListView1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1238,[System.Int32]610)) +$ListView1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1234,[System.Int32]553)) $ListView1.TabIndex = [System.Int32]0 $ListView1.UseCompatibleStateImageBehavior = $false $ListView1.View = [System.Windows.Forms.View]::Details @@ -72,7 +106,7 @@ $Button1.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.Anch $Button1.FlatStyle = [System.Windows.Forms.FlatStyle]::System $Button1.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) $Button1.ForeColor = [System.Drawing.SystemColors]::ActiveCaptionText -$Button1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]12,[System.Int32]628)) +$Button1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]562)) $Button1.Name = [System.String]'Button1' $Button1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]234,[System.Int32]33)) $Button1.TabIndex = [System.Int32]1 @@ -88,7 +122,7 @@ $Button2.Enabled = $false $Button2.FlatStyle = [System.Windows.Forms.FlatStyle]::System $Button2.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) $Button2.ForeColor = [System.Drawing.SystemColors]::ActiveCaptionText -$Button2.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]252,[System.Int32]628)) +$Button2.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]253,[System.Int32]562)) $Button2.Name = [System.String]'Button2' $Button2.RightToLeft = [System.Windows.Forms.RightToLeft]::No $Button2.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]234,[System.Int32]33)) @@ -101,9 +135,9 @@ $Button2.add_Click($Button2_Click) # $Label1.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) $Label1.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Trebuchet MS',[System.Single]11.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) -$Label1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]647,[System.Int32]628)) +$Label1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]648,[System.Int32]562)) $Label1.Name = [System.String]'Label1' -$Label1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]522,[System.Int32]33)) +$Label1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]575,[System.Int32]33)) $Label1.TabIndex = [System.Int32]2 $Label1.Text = [System.String]'Check console output for progress on update installation!' $Label1.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter @@ -127,27 +161,226 @@ $Button3.add_Click($Button3_Click) $CheckBox1.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left) $CheckBox1.FlatStyle = [System.Windows.Forms.FlatStyle]::System $CheckBox1.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) -$CheckBox1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]492,[System.Int32]628)) +$CheckBox1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]493,[System.Int32]562)) $CheckBox1.Name = [System.String]'CheckBox1' $CheckBox1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]149,[System.Int32]33)) $CheckBox1.TabIndex = [System.Int32]4 -$CheckBox1.Text = [System.String]' Verbose output' +$CheckBox1.Text = [System.String]'Verbose output' $CheckBox1.UseVisualStyleBackColor = $true # +#Label2 +# +$Label2.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left) +$Label2.BackColor = [System.Drawing.SystemColors]::Control +$Label2.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Trebuchet MS',[System.Single]11.25)) +$Label2.ForeColor = [System.Drawing.SystemColors]::ActiveCaptionText +$Label2.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]12,[System.Int32]628)) +$Label2.Name = [System.String]'Label2' +$Label2.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$Label2.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]146,[System.Int32]33)) +$Label2.TabIndex = [System.Int32]2 +$Label2.Text = [System.String]'Choose an option:' +$Label2.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft +# +#UpdateInstallationPanel +# +$UpdateInstallationPanel.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) +$UpdateInstallationPanel.Controls.Add($ListView1) +$UpdateInstallationPanel.Controls.Add($CheckBox1) +$UpdateInstallationPanel.Controls.Add($Label1) +$UpdateInstallationPanel.Controls.Add($Button1) +$UpdateInstallationPanel.Controls.Add($Button2) +$UpdateInstallationPanel.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]12,[System.Int32]12)) +$UpdateInstallationPanel.Name = [System.String]'UpdateInstallationPanel' +$UpdateInstallationPanel.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1238,[System.Int32]610)) +$UpdateInstallationPanel.TabIndex = [System.Int32]5 +# +#Button4 +# +$Button4.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left) +$Button4.BackColor = [System.Drawing.SystemColors]::Control +$Button4.FlatStyle = [System.Windows.Forms.FlatStyle]::System +$Button4.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) +$Button4.ForeColor = [System.Drawing.SystemColors]::ActiveCaptionText +$Button4.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]164,[System.Int32]628)) +$Button4.Name = [System.String]'Button4' +$Button4.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$Button4.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]112,[System.Int32]33)) +$Button4.TabIndex = [System.Int32]3 +$Button4.Text = [System.String]'Install Updates' +$Button4.UseVisualStyleBackColor = $true +$Button4.add_Click($Button4_Click) +# +#Button5 +# +$Button5.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left) +$Button5.BackColor = [System.Drawing.SystemColors]::Control +$Button5.FlatStyle = [System.Windows.Forms.FlatStyle]::System +$Button5.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) +$Button5.ForeColor = [System.Drawing.SystemColors]::ActiveCaptionText +$Button5.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]282,[System.Int32]628)) +$Button5.Name = [System.String]'Button5' +$Button5.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$Button5.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]112,[System.Int32]33)) +$Button5.TabIndex = [System.Int32]3 +$Button5.Text = [System.String]'Get Update History' +$Button5.UseVisualStyleBackColor = $true +$Button5.add_Click($Button5_Click) +# +#UpdateHistoryPanel +# +$UpdateHistoryPanel.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) +$UpdateHistoryPanel.Controls.Add($ListView7) +$UpdateHistoryPanel.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]12,[System.Int32]11)) +$UpdateHistoryPanel.Name = [System.String]'UpdateHistoryPanel' +$UpdateHistoryPanel.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1238,[System.Int32]611)) +$UpdateHistoryPanel.TabIndex = [System.Int32]6 +$UpdateHistoryPanel.Visible = $false +# +#ListView7 +# +$ListView7.Columns.AddRange([System.Windows.Forms.ColumnHeader[]]@($ColumnHeader6,$ColumnHeader7,$ColumnHeader8,$ColumnHeader9,$ColumnHeader10)) +$ListView7.Dock = [System.Windows.Forms.DockStyle]::Fill +$ListView7.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0))) +$ListView7.FullRowSelect = $true +$ListView7.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]0,[System.Int32]0)) +$ListView7.Name = [System.String]'ListView7' +$ListView7.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1238,[System.Int32]611)) +$ListView7.TabIndex = [System.Int32]0 +$ListView7.UseCompatibleStateImageBehavior = $false +$ListView7.View = [System.Windows.Forms.View]::Details +# +#ColumnHeader6 +# +$ColumnHeader6.Text = [System.String]'Computer Name' +$ColumnHeader6.Width = [System.Int32]142 +# +#ColumnHeader7 +# +$ColumnHeader7.Text = [System.String]'Operation' +$ColumnHeader7.Width = [System.Int32]100 +# +#ColumnHeader8 +# +$ColumnHeader8.Text = [System.String]'Result' +$ColumnHeader8.Width = [System.Int32]147 +# +#ColumnHeader9 +# +$ColumnHeader9.Text = [System.String]'Date' +$ColumnHeader9.Width = [System.Int32]128 +# +#ColumnHeader10 +# +$ColumnHeader10.Text = [System.String]'Name' +$ColumnHeader10.Width = [System.Int32]695 +# +#ListView2 +# +$ListView2.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) +$ListView2.BackColor = [System.Drawing.SystemColors]::Window +$ListView2.CheckBoxes = $true +$ListView2.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) +$ListView2.ForeColor = [System.Drawing.SystemColors]::WindowText +$ListView2.FullRowSelect = $true +$ListView2.ImeMode = [System.Windows.Forms.ImeMode]::NoControl +$ListView2.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]13)) +$ListView2.Name = [System.String]'ListView2' +$ListView2.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$ListView2.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1232,[System.Int32]553)) +$ListView2.TabIndex = [System.Int32]0 +$ListView2.UseCompatibleStateImageBehavior = $false +$ListView2.View = [System.Windows.Forms.View]::Details +# +#ListView3 +# +$ListView3.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) +$ListView3.BackColor = [System.Drawing.SystemColors]::Window +$ListView3.CheckBoxes = $true +$ListView3.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) +$ListView3.ForeColor = [System.Drawing.SystemColors]::WindowText +$ListView3.FullRowSelect = $true +$ListView3.ImeMode = [System.Windows.Forms.ImeMode]::NoControl +$ListView3.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]13)) +$ListView3.Name = [System.String]'ListView3' +$ListView3.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$ListView3.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1232,[System.Int32]553)) +$ListView3.TabIndex = [System.Int32]0 +$ListView3.UseCompatibleStateImageBehavior = $false +$ListView3.View = [System.Windows.Forms.View]::Details +# +#ListView4 +# +$ListView4.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) +$ListView4.BackColor = [System.Drawing.SystemColors]::Window +$ListView4.CheckBoxes = $true +$ListView4.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) +$ListView4.ForeColor = [System.Drawing.SystemColors]::WindowText +$ListView4.FullRowSelect = $true +$ListView4.ImeMode = [System.Windows.Forms.ImeMode]::NoControl +$ListView4.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]13)) +$ListView4.Name = [System.String]'ListView4' +$ListView4.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$ListView4.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1232,[System.Int32]553)) +$ListView4.TabIndex = [System.Int32]0 +$ListView4.UseCompatibleStateImageBehavior = $false +$ListView4.View = [System.Windows.Forms.View]::Details +# +#ListView5 +# +$ListView5.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) +$ListView5.BackColor = [System.Drawing.SystemColors]::Window +$ListView5.CheckBoxes = $true +$ListView5.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) +$ListView5.ForeColor = [System.Drawing.SystemColors]::WindowText +$ListView5.FullRowSelect = $true +$ListView5.ImeMode = [System.Windows.Forms.ImeMode]::NoControl +$ListView5.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]14,[System.Int32]11)) +$ListView5.Name = [System.String]'ListView5' +$ListView5.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$ListView5.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1232,[System.Int32]553)) +$ListView5.TabIndex = [System.Int32]0 +$ListView5.UseCompatibleStateImageBehavior = $false +$ListView5.View = [System.Windows.Forms.View]::Details +# +#ListView6 +# +$ListView6.Anchor = ([System.Windows.Forms.AnchorStyles][System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left -bor [System.Windows.Forms.AnchorStyles]::Right) +$ListView6.BackColor = [System.Drawing.SystemColors]::Window +$ListView6.CheckBoxes = $true +$ListView6.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Tahoma',[System.Single]8.25)) +$ListView6.ForeColor = [System.Drawing.SystemColors]::WindowText +$ListView6.FullRowSelect = $true +$ListView6.ImeMode = [System.Windows.Forms.ImeMode]::NoControl +$ListView6.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]14,[System.Int32]11)) +$ListView6.Name = [System.String]'ListView6' +$ListView6.RightToLeft = [System.Windows.Forms.RightToLeft]::No +$ListView6.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1232,[System.Int32]553)) +$ListView6.TabIndex = [System.Int32]0 +$ListView6.UseCompatibleStateImageBehavior = $false +$ListView6.View = [System.Windows.Forms.View]::Details +# #Form1 # $Form1.ClientSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]1262,[System.Int32]673)) -$Form1.Controls.Add($CheckBox1) +$Form1.Controls.Add($UpdateHistoryPanel) +$Form1.Controls.Add($UpdateInstallationPanel) $Form1.Controls.Add($Button3) -$Form1.Controls.Add($Label1) -$Form1.Controls.Add($Button1) -$Form1.Controls.Add($ListView1) -$Form1.Controls.Add($Button2) +$Form1.Controls.Add($Label2) +$Form1.Controls.Add($Button4) +$Form1.Controls.Add($Button5) +$Form1.Controls.Add($ListView2) +$Form1.Controls.Add($ListView3) +$Form1.Controls.Add($ListView4) +$Form1.Controls.Add($ListView5) +$Form1.Controls.Add($ListView6) $Form1.ForeColor = [System.Drawing.SystemColors]::ActiveCaptionText $Form1.MaximumSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]4096,[System.Int32]4096)) $Form1.MinimumSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]600,[System.Int32]240)) $Form1.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen $Form1.Text = [System.String]'UpdGUI' +$UpdateInstallationPanel.ResumeLayout($false) +$UpdateHistoryPanel.ResumeLayout($false) $Form1.ResumeLayout($false) Add-Member -InputObject $Form1 -Name ListView1 -Value $ListView1 -MemberType NoteProperty Add-Member -InputObject $Form1 -Name ColumnHeader5 -Value $ColumnHeader5 -MemberType NoteProperty @@ -160,5 +393,21 @@ Add-Member -InputObject $Form1 -Name Button2 -Value $Button2 -MemberType NotePro Add-Member -InputObject $Form1 -Name Label1 -Value $Label1 -MemberType NoteProperty Add-Member -InputObject $Form1 -Name Button3 -Value $Button3 -MemberType NoteProperty Add-Member -InputObject $Form1 -Name CheckBox1 -Value $CheckBox1 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name Label2 -Value $Label2 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name UpdateInstallationPanel -Value $UpdateInstallationPanel -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name Button4 -Value $Button4 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name Button5 -Value $Button5 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name UpdateHistoryPanel -Value $UpdateHistoryPanel -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ListView7 -Value $ListView7 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ColumnHeader6 -Value $ColumnHeader6 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ColumnHeader7 -Value $ColumnHeader7 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ColumnHeader8 -Value $ColumnHeader8 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ColumnHeader9 -Value $ColumnHeader9 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ColumnHeader10 -Value $ColumnHeader10 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ListView2 -Value $ListView2 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ListView3 -Value $ListView3 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ListView4 -Value $ListView4 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ListView5 -Value $ListView5 -MemberType NoteProperty +Add-Member -InputObject $Form1 -Name ListView6 -Value $ListView6 -MemberType NoteProperty } . InitializeComponent diff --git a/updgui.ps1 b/updgui.ps1 index ac949e8..cbb1e8b 100644 --- a/updgui.ps1 +++ b/updgui.ps1 @@ -1,3 +1,26 @@ +$Button5_Click = { + $UpdateInstallationPanel.Visible = $false + $UpdateHistoryPanel.Visible = $true + + Invoke-InfoLogging "Getting installed updates..." + $ListView7.Items.Clear() + $updateHistory = Get-WindowsUpdatesFromHistory + if ($updateHistory.Count -gt 0) { + for ($i = 0; $i -lt $updateHistory.Count; $i++) { + $ListView7.Items.Add([System.Windows.Forms.ListViewItem]::new([string[]]@( + $updateHistory[$i].ComputerName, + $updateHistory[$i].Operationname, + $updateHistory[$i].Result, + $updateHistory[$i].Date, + $updateHistory[$i].Title + ))) + } + } +} +$Button4_Click = { + $UpdateInstallationPanel.Visible = $true + $UpdateHistoryPanel.Visible = $false +} $Button3_Click = { . (Join-Path $PSScriptRoot 'aboutform.designer.ps1') $AboutForm.ShowDialog($Form1) @@ -27,25 +50,26 @@ $Button2_Click = { if ($ListView1.CheckedItems.Count -ge $ListView1.Items.Count) { Invoke-InfoLogging "Installing $($ListView1.Items.Count) update(s)..." if ($CheckBox1.Checked -eq $true) { - Install-WindowsUpdate -Verbose -Confirm:$false + Install-WindowsUpdate -Verbose -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true } else { - Install-WindowsUpdate -Confirm:$false + Install-WindowsUpdate -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true } + Invoke-InfoLogging "Installation of updates succeeded. You may need to restart your computer for changes to take effect." $ListView1.Items.Clear() } else { foreach ($selLVI in $checkedUpdates) { Invoke-InfoLogging "Installing update with name: `"$($selLVI.SubItems[4].Text)`" (KB Article ID: $($selLVI.SubItems[2].Text))..." if ($selLVI.Subitems[2].Text -ne "") { if ($CheckBox1.Checked -eq $true) { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -Verbose + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -Verbose -IgnoreReboot:$true -IgnoreRebootRequired:$true } else { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -KBArticleID $selLVI.SubItems[2].Text -Install -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true } } else { if ($CheckBox1.Checked -eq $true) { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -Verbose + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -Verbose -IgnoreReboot:$true -IgnoreRebootRequired:$true } else { - Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false + Get-WindowsUpdate -ComputerName "$($selLVI.SubItems[1].Text)" -Title "$($selLVI.SubItems[4].Text)" -Install -Confirm:$false -IgnoreReboot:$true -IgnoreRebootRequired:$true } } if ($?) { @@ -56,6 +80,7 @@ $Button2_Click = { Invoke-InfoLogging "Error information: $_.Exception.Message" } } + Invoke-InfoLogging "You may need to restart your computer for changes to take effect." } $Label1.Visible = $false $CheckBox1.Enabled = $true @@ -101,6 +126,10 @@ function Invoke-InfoLogging { Write-Host "[$(Get-Date)] $message" } +function Get-WindowsUpdatesFromHistory { + return Get-WUHistory +} + function Check-PSWindowsUpdate { try { Invoke-InfoLogging "Checking PSWindowsUpdate..." @@ -125,7 +154,7 @@ function Check-PSWindowsUpdate { } function Show-StartupGraphic { - $verConst = "v.Next" + $verConst = "1.1" # Show a cool graphic on startup Write-Host -NoNewline "`n`n" Write-Host " dddddddd " diff --git a/updgui.resources.ps1 b/updgui.resources.ps1 index f7e8fa7..f2b55b4 100644 --- a/updgui.resources.ps1 +++ b/updgui.resources.ps1 @@ -1,16 +1,32 @@ & { $BinaryFormatter = New-Object -TypeName System.Runtime.Serialization.Formatters.Binary.BinaryFormatter @{ -'Button2.Name' = 'Button2' -'CheckBox1.Name' = 'CheckBox1' 'ColumnHeader3.Name' = 'ColumnHeader3' -'ListView1.Name' = 'ListView1' -'ColumnHeader5.Name' = 'ColumnHeader5' +'ColumnHeader1.Name' = 'ColumnHeader1' +'Button1.Name' = 'Button1' +'ListView6.Name' = 'ListView6' +'ListView3.Name' = 'ListView3' +'ColumnHeader7.Name' = 'ColumnHeader7' +'ColumnHeader10.Name' = 'ColumnHeader10' +'ListView2.Name' = 'ListView2' +'Label2.Name' = 'Label2' 'Button3.Name' = 'Button3' +'ListView5.Name' = 'ListView5' +'UpdateHistoryPanel.Name' = 'UpdateHistoryPanel' +'ColumnHeader8.Name' = 'ColumnHeader8' +'Button5.Name' = 'Button5' +'ColumnHeader9.Name' = 'ColumnHeader9' +'CheckBox1.Name' = 'CheckBox1' +'UpdateInstallationPanel.Name' = 'UpdateInstallationPanel' +'ColumnHeader6.Name' = 'ColumnHeader6' 'ColumnHeader4.Name' = 'ColumnHeader4' +'ColumnHeader5.Name' = 'ColumnHeader5' 'Label1.Name' = 'Label1' -'ColumnHeader1.Name' = 'ColumnHeader1' -'ColumnHeader2.Name' = 'ColumnHeader2' -'Button1.Name' = 'Button1' +'ListView4.Name' = 'ListView4' +'ListView1.Name' = 'ListView1' +'ListView7.Name' = 'ListView7' '$this.Name' = 'Form1' +'ColumnHeader2.Name' = 'ColumnHeader2' +'Button4.Name' = 'Button4' +'Button2.Name' = 'Button2' } } \ No newline at end of file