Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PowerShell GUI to Hide/Show Driver Updates with Detailed Information
- # Requires PSWindowsUpdate module and Administrator privileges
- #Requires -RunAsAdministrator
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- # Install PSWindowsUpdate module if not present
- if (!(Get-Module -ListAvailable -Name PSWindowsUpdate)) {
- Write-Host "Installing PSWindowsUpdate module..."
- Install-Module PSWindowsUpdate -Force -Scope CurrentUser
- }
- try {
- Import-Module PSWindowsUpdate -Force -ErrorAction Stop
- Write-Host "PSWindowsUpdate module loaded successfully"
- }
- catch {
- [System.Windows.Forms.MessageBox]::Show("Failed to load PSWindowsUpdate module. Please install it manually using: Install-Module PSWindowsUpdate -Force", "Module Error")
- exit
- }
- # Create main form
- $form = New-Object System.Windows.Forms.Form
- $form.Text = 'Hide/Show Driver Updates PS / Free(F) uncKot / provided AS IS'
- $form.Size = New-Object System.Drawing.Size(1000,550)
- $form.StartPosition = 'CenterScreen'
- # Status label
- $statusLabel = New-Object System.Windows.Forms.Label
- $statusLabel.Location = New-Object System.Drawing.Point(10,10)
- $statusLabel.Size = New-Object System.Drawing.Size(960,20)
- $statusLabel.Text = 'Click "Scan for Updates" to begin'
- $form.Controls.Add($statusLabel)
- # ListView for updates
- $listView = New-Object System.Windows.Forms.ListView
- $listView.Location = New-Object System.Drawing.Point(10,40)
- $listView.Size = New-Object System.Drawing.Size(660,330)
- $listView.View = 'Details'
- $listView.CheckBoxes = $true
- $listView.FullRowSelect = $true
- $listView.GridLines = $true
- $listView.MultiSelect = $false
- # Add columns
- [void]$listView.Columns.Add('Title', 280)
- [void]$listView.Columns.Add('KB Article', 85)
- [void]$listView.Columns.Add('Size', 60)
- [void]$listView.Columns.Add('Status', 70)
- [void]$listView.Columns.Add('Severity', 70)
- $form.Controls.Add($listView)
- # Information GroupBox - RESIZED to align with buttons + label
- $infoBox = New-Object System.Windows.Forms.GroupBox
- $infoBox.Location = New-Object System.Drawing.Point(680,40)
- $infoBox.Size = New-Object System.Drawing.Size(300,410)
- $infoBox.Text = 'Update Information'
- $form.Controls.Add($infoBox)
- # Information TextBox (inside GroupBox) - RESIZED
- $infoTextBox = New-Object System.Windows.Forms.TextBox
- $infoTextBox.Location = New-Object System.Drawing.Point(10,20)
- $infoTextBox.Size = New-Object System.Drawing.Size(280,380)
- $infoTextBox.Multiline = $true
- $infoTextBox.ScrollBars = 'Vertical'
- $infoTextBox.ReadOnly = $true
- $infoTextBox.Font = New-Object System.Drawing.Font("Consolas",9)
- $infoTextBox.BackColor = [System.Drawing.Color]::White
- $infoBox.Controls.Add($infoTextBox)
- # Scan button
- $scanButton = New-Object System.Windows.Forms.Button
- $scanButton.Location = New-Object System.Drawing.Point(10,380)
- $scanButton.Size = New-Object System.Drawing.Size(150,30)
- $scanButton.Text = 'Scan for Updates'
- $form.Controls.Add($scanButton)
- # Hide button
- $hideButton = New-Object System.Windows.Forms.Button
- $hideButton.Location = New-Object System.Drawing.Point(170,380)
- $hideButton.Size = New-Object System.Drawing.Size(150,30)
- $hideButton.Text = 'Hide Selected'
- $hideButton.Enabled = $false
- $form.Controls.Add($hideButton)
- # Show button
- $showButton = New-Object System.Windows.Forms.Button
- $showButton.Location = New-Object System.Drawing.Point(330,380)
- $showButton.Size = New-Object System.Drawing.Size(150,30)
- $showButton.Text = 'Show Selected'
- $showButton.Enabled = $false
- $form.Controls.Add($showButton)
- # Refresh button
- $refreshButton = New-Object System.Windows.Forms.Button
- $refreshButton.Location = New-Object System.Drawing.Point(490,380)
- $refreshButton.Size = New-Object System.Drawing.Size(150,30)
- $refreshButton.Text = 'Refresh Info'
- $refreshButton.Enabled = $false
- $form.Controls.Add($refreshButton)
- # Progress bar
- $progressBar = New-Object System.Windows.Forms.ProgressBar
- $progressBar.Location = New-Object System.Drawing.Point(10,420)
- $progressBar.Size = New-Object System.Drawing.Size(660,20)
- $progressBar.Style = 'Marquee'
- $progressBar.Visible = $false
- $form.Controls.Add($progressBar)
- # Details Label (below buttons)
- $detailsLabel = New-Object System.Windows.Forms.Label
- $detailsLabel.Location = New-Object System.Drawing.Point(10,450)
- $detailsLabel.Size = New-Object System.Drawing.Size(660,150)
- $detailsLabel.Font = New-Object System.Drawing.Font("Segoe UI",9)
- $detailsLabel.Text = ''
- $form.Controls.Add($detailsLabel)
- # Function to safely get property value
- function Get-SafeProperty {
- param(
- $object,
- $propertyName,
- $default = 'N/A'
- )
- try {
- $value = $object.$propertyName
- if ($null -eq $value -or $value -eq '') {
- return $default
- }
- return $value
- }
- catch {
- return $default
- }
- }
- # Function to format size
- function Format-Size {
- param([long]$Bytes)
- if ($Bytes -eq 0) { return "0 B" }
- $sizes = 'B','KB','MB','GB','TB'
- $order = [Math]::Floor([Math]::Log($Bytes, 1024))
- $num = [Math]::Round($Bytes / [Math]::Pow(1024, $order), 2)
- return "{0:N2} {1}" -f $num, $sizes[$order]
- }
- # Function to display detailed update information
- function Show-UpdateDetails {
- param($update)
- if ($null -eq $update) {
- $infoTextBox.Text = "No update selected"
- return
- }
- # Safely get properties
- $title = Get-SafeProperty $update 'Title'
- $kbArticles = if ($update.KBArticleIDs.Count -gt 0) { $update.KBArticleIDs -join ', ' } else { 'N/A' }
- $updateID = Get-SafeProperty $update.Identity 'UpdateID'
- $revision = Get-SafeProperty $update.Identity 'RevisionNumber'
- $size = Format-Size $update.MaxDownloadSize
- $categories = if ($update.Categories.Count -gt 0) {
- ($update.Categories | ForEach-Object { " - $($_.Name)" }) -join "`n"
- } else {
- ' N/A'
- }
- $severity = Get-SafeProperty $update 'MsrcSeverity'
- $description = Get-SafeProperty $update 'Description'
- $supportUrl = Get-SafeProperty $update 'SupportUrl'
- $moreInfo = if ($update.MoreInfoUrls.Count -gt 0) {
- $update.MoreInfoUrls -join "`n"
- } else {
- 'N/A'
- }
- # Format dates safely
- $releaseDate = if ($update.ReleaseDate) {
- $update.ReleaseDate.ToString('yyyy-MM-dd HH:mm')
- } else {
- 'N/A'
- }
- $lastChange = if ($update.LastDeploymentChangeTime) {
- $update.LastDeploymentChangeTime.ToString('yyyy-MM-dd HH:mm')
- } else {
- 'N/A'
- }
- # Status flags
- $statusFlags = @()
- if ($update.IsHidden) { $statusFlags += 'Hidden' }
- if ($update.IsDownloaded) { $statusFlags += 'Downloaded' }
- if ($update.IsInstalled) { $statusFlags += 'Installed' }
- if ($update.IsMandatory) { $statusFlags += 'Mandatory' }
- if ($update.RebootRequired) { $statusFlags += 'Reboot Required' }
- if ($statusFlags.Count -eq 0) { $statusFlags += 'Visible, Not Downloaded' }
- $details = @"
- UPDATE DETAILS
- $('=' * 40)
- Title:
- $title
- KB Article ID:
- $kbArticles
- Update ID:
- $updateID
- Revision:
- $revision
- Size:
- $size
- Categories:
- $categories
- Severity:
- $severity
- Status:
- $($statusFlags -join ', ')
- Last Deployment Change:
- $lastChange
- Release Date:
- $releaseDate
- Support URL:
- $supportUrl
- Description:
- $description
- More Information:
- $moreInfo
- "@
- $infoTextBox.Text = $details
- }
- # ListView selection changed event
- $listView.Add_SelectedIndexChanged({
- if ($listView.SelectedItems.Count -gt 0) {
- $selectedItem = $listView.SelectedItems[0]
- $update = $selectedItem.Tag
- Show-UpdateDetails -update $update
- # Also show brief info in details label
- $categoryNames = if ($update.Categories.Count -gt 0) {
- $update.Categories.Name -join ', '
- } else {
- 'N/A'
- }
- $releaseInfo = if ($update.ReleaseDate) {
- "Release Date: $($update.ReleaseDate.ToShortDateString())"
- } else {
- "Release Date: N/A"
- }
- $detailsLabel.Text = "Selected: $($update.Title)`n$releaseInfo | Categories: $categoryNames"
- }
- })
- # Add tooltip functionality
- $tooltip = New-Object System.Windows.Forms.ToolTip
- $tooltip.AutoPopDelay = 10000
- $tooltip.InitialDelay = 500
- $tooltip.ReshowDelay = 100
- # ListView mouse move event for tooltips
- $listView.Add_MouseMove({
- param($sender, $e)
- $item = $listView.GetItemAt($e.X, $e.Y)
- if ($null -ne $item) {
- $update = $item.Tag
- # Safely build tooltip text
- $kbText = if ($update.KBArticleIDs.Count -gt 0) {
- $update.KBArticleIDs -join ', '
- } else {
- 'N/A'
- }
- $sizeText = Format-Size $update.MaxDownloadSize
- $severityText = Get-SafeProperty $update 'MsrcSeverity'
- $releaseText = if ($update.ReleaseDate) {
- $update.ReleaseDate.ToShortDateString()
- } else {
- 'N/A'
- }
- $tooltipText = @"
- $($update.Title)
- KB: $kbText
- Size: $sizeText
- Severity: $severityText
- Release: $releaseText
- "@
- $tooltip.SetToolTip($listView, $tooltipText)
- }
- })
- # Scan button click event
- $scanButton.Add_Click({
- $listView.Items.Clear()
- $infoTextBox.Text = "Scanning..."
- $statusLabel.Text = 'Scanning for driver updates...'
- $progressBar.Visible = $true
- $scanButton.Enabled = $false
- $form.Refresh()
- try {
- # Scan for all driver updates including hidden ones
- $updates = Get-WindowsUpdate -UpdateType Driver -WithHidden
- foreach ($update in $updates) {
- $item = New-Object System.Windows.Forms.ListViewItem($update.Title)
- # Get KB Article ID
- $kbArticle = if ($update.KBArticleIDs.Count -gt 0) {
- "KB" + $update.KBArticleIDs[0]
- } else {
- "N/A"
- }
- [void]$item.SubItems.Add($kbArticle)
- # Format size
- $sizeText = Format-Size $update.MaxDownloadSize
- [void]$item.SubItems.Add($sizeText)
- # Get status
- $status = if ($update.IsHidden) { "Hidden" } else { "Visible" }
- [void]$item.SubItems.Add($status)
- # Get severity
- $severity = Get-SafeProperty $update 'MsrcSeverity'
- [void]$item.SubItems.Add($severity)
- # Store the update object for later use
- $item.Tag = $update
- [void]$listView.Items.Add($item)
- }
- $statusLabel.Text = "Found $($updates.Count) driver update(s)"
- $infoTextBox.Text = "Select an update to view details"
- }
- catch {
- [System.Windows.Forms.MessageBox]::Show("Error scanning for updates: $_", "Scan Error")
- $statusLabel.Text = "Error scanning for updates"
- $infoTextBox.Text = "Error: $_"
- }
- $progressBar.Visible = $false
- $scanButton.Enabled = $true
- $hideButton.Enabled = $true
- $showButton.Enabled = $true
- $refreshButton.Enabled = $true
- })
- # Hide button click event
- $hideButton.Add_Click({
- $selectedCount = 0
- $errorCount = 0
- foreach ($item in $listView.CheckedItems) {
- $update = $item.Tag
- try {
- if ($update.KBArticleIDs.Count -gt 0) {
- Get-WindowsUpdate -KBArticleID $update.KBArticleIDs[0] -Hide -Confirm:$false | Out-Null
- } else {
- Hide-WindowsUpdate -Title $update.Title -Confirm:$false | Out-Null
- }
- $item.SubItems[3].Text = "Hidden"
- $update.IsHidden = $true
- $item.Checked = $false
- $selectedCount++
- }
- catch {
- $errorCount++
- }
- }
- if ($errorCount -gt 0) {
- [System.Windows.Forms.MessageBox]::Show("Failed to hide $errorCount update(s). Make sure you're running as Administrator.", "Warning")
- }
- $statusLabel.Text = "Hidden $selectedCount update(s)"
- })
- # Show button click event
- $showButton.Add_Click({
- $selectedCount = 0
- $errorCount = 0
- foreach ($item in $listView.CheckedItems) {
- $update = $item.Tag
- try {
- if ($update.KBArticleIDs.Count -gt 0) {
- Show-WindowsUpdate -KBArticleID $update.KBArticleIDs[0] -Confirm:$false | Out-Null
- } else {
- Get-WindowsUpdate -Title $update.Title -WithHidden -Hide:$false -Confirm:$false | Out-Null
- }
- $item.SubItems[3].Text = "Visible"
- $update.IsHidden = $false
- $item.Checked = $false
- $selectedCount++
- }
- catch {
- $errorCount++
- }
- }
- if ($errorCount -gt 0) {
- [System.Windows.Forms.MessageBox]::Show("Failed to show $errorCount update(s). Make sure you're running as Administrator.", "Warning")
- }
- $statusLabel.Text = "Unhidden $selectedCount update(s)"
- })
- # Refresh button click event
- $refreshButton.Add_Click({
- if ($listView.SelectedItems.Count -gt 0) {
- $selectedItem = $listView.SelectedItems[0]
- $update = $selectedItem.Tag
- Show-UpdateDetails -update $update
- }
- })
- # Show the form
- [void]$form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment