Guest User

WUShowHidePS

a guest
Jan 18th, 2026
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.42 KB | Source Code | 0 0
  1. # PowerShell GUI to Hide/Show Driver Updates with Detailed Information
  2. # Requires PSWindowsUpdate module and Administrator privileges
  3.  
  4. #Requires -RunAsAdministrator
  5.  
  6. Add-Type -AssemblyName System.Windows.Forms
  7. Add-Type -AssemblyName System.Drawing
  8.  
  9. # Install PSWindowsUpdate module if not present
  10. if (!(Get-Module -ListAvailable -Name PSWindowsUpdate)) {
  11. Write-Host "Installing PSWindowsUpdate module..."
  12. Install-Module PSWindowsUpdate -Force -Scope CurrentUser
  13. }
  14.  
  15. try {
  16. Import-Module PSWindowsUpdate -Force -ErrorAction Stop
  17. Write-Host "PSWindowsUpdate module loaded successfully"
  18. }
  19. catch {
  20. [System.Windows.Forms.MessageBox]::Show("Failed to load PSWindowsUpdate module. Please install it manually using: Install-Module PSWindowsUpdate -Force", "Module Error")
  21. exit
  22. }
  23.  
  24. # Create main form
  25. $form = New-Object System.Windows.Forms.Form
  26. $form.Text = 'Hide/Show Driver Updates PS / Free(F) uncKot / provided AS IS'
  27. $form.Size = New-Object System.Drawing.Size(1000,550)
  28. $form.StartPosition = 'CenterScreen'
  29.  
  30. # Status label
  31. $statusLabel = New-Object System.Windows.Forms.Label
  32. $statusLabel.Location = New-Object System.Drawing.Point(10,10)
  33. $statusLabel.Size = New-Object System.Drawing.Size(960,20)
  34. $statusLabel.Text = 'Click "Scan for Updates" to begin'
  35. $form.Controls.Add($statusLabel)
  36.  
  37. # ListView for updates
  38. $listView = New-Object System.Windows.Forms.ListView
  39. $listView.Location = New-Object System.Drawing.Point(10,40)
  40. $listView.Size = New-Object System.Drawing.Size(660,330)
  41. $listView.View = 'Details'
  42. $listView.CheckBoxes = $true
  43. $listView.FullRowSelect = $true
  44. $listView.GridLines = $true
  45. $listView.MultiSelect = $false
  46.  
  47. # Add columns
  48. [void]$listView.Columns.Add('Title', 280)
  49. [void]$listView.Columns.Add('KB Article', 85)
  50. [void]$listView.Columns.Add('Size', 60)
  51. [void]$listView.Columns.Add('Status', 70)
  52. [void]$listView.Columns.Add('Severity', 70)
  53.  
  54. $form.Controls.Add($listView)
  55.  
  56. # Information GroupBox - RESIZED to align with buttons + label
  57. $infoBox = New-Object System.Windows.Forms.GroupBox
  58. $infoBox.Location = New-Object System.Drawing.Point(680,40)
  59. $infoBox.Size = New-Object System.Drawing.Size(300,410)
  60. $infoBox.Text = 'Update Information'
  61. $form.Controls.Add($infoBox)
  62.  
  63. # Information TextBox (inside GroupBox) - RESIZED
  64. $infoTextBox = New-Object System.Windows.Forms.TextBox
  65. $infoTextBox.Location = New-Object System.Drawing.Point(10,20)
  66. $infoTextBox.Size = New-Object System.Drawing.Size(280,380)
  67. $infoTextBox.Multiline = $true
  68. $infoTextBox.ScrollBars = 'Vertical'
  69. $infoTextBox.ReadOnly = $true
  70. $infoTextBox.Font = New-Object System.Drawing.Font("Consolas",9)
  71. $infoTextBox.BackColor = [System.Drawing.Color]::White
  72. $infoBox.Controls.Add($infoTextBox)
  73.  
  74. # Scan button
  75. $scanButton = New-Object System.Windows.Forms.Button
  76. $scanButton.Location = New-Object System.Drawing.Point(10,380)
  77. $scanButton.Size = New-Object System.Drawing.Size(150,30)
  78. $scanButton.Text = 'Scan for Updates'
  79. $form.Controls.Add($scanButton)
  80.  
  81. # Hide button
  82. $hideButton = New-Object System.Windows.Forms.Button
  83. $hideButton.Location = New-Object System.Drawing.Point(170,380)
  84. $hideButton.Size = New-Object System.Drawing.Size(150,30)
  85. $hideButton.Text = 'Hide Selected'
  86. $hideButton.Enabled = $false
  87. $form.Controls.Add($hideButton)
  88.  
  89. # Show button
  90. $showButton = New-Object System.Windows.Forms.Button
  91. $showButton.Location = New-Object System.Drawing.Point(330,380)
  92. $showButton.Size = New-Object System.Drawing.Size(150,30)
  93. $showButton.Text = 'Show Selected'
  94. $showButton.Enabled = $false
  95. $form.Controls.Add($showButton)
  96.  
  97. # Refresh button
  98. $refreshButton = New-Object System.Windows.Forms.Button
  99. $refreshButton.Location = New-Object System.Drawing.Point(490,380)
  100. $refreshButton.Size = New-Object System.Drawing.Size(150,30)
  101. $refreshButton.Text = 'Refresh Info'
  102. $refreshButton.Enabled = $false
  103. $form.Controls.Add($refreshButton)
  104.  
  105. # Progress bar
  106. $progressBar = New-Object System.Windows.Forms.ProgressBar
  107. $progressBar.Location = New-Object System.Drawing.Point(10,420)
  108. $progressBar.Size = New-Object System.Drawing.Size(660,20)
  109. $progressBar.Style = 'Marquee'
  110. $progressBar.Visible = $false
  111. $form.Controls.Add($progressBar)
  112.  
  113. # Details Label (below buttons)
  114. $detailsLabel = New-Object System.Windows.Forms.Label
  115. $detailsLabel.Location = New-Object System.Drawing.Point(10,450)
  116. $detailsLabel.Size = New-Object System.Drawing.Size(660,150)
  117. $detailsLabel.Font = New-Object System.Drawing.Font("Segoe UI",9)
  118. $detailsLabel.Text = ''
  119. $form.Controls.Add($detailsLabel)
  120.  
  121. # Function to safely get property value
  122. function Get-SafeProperty {
  123. param(
  124. $object,
  125. $propertyName,
  126. $default = 'N/A'
  127. )
  128.  
  129. try {
  130. $value = $object.$propertyName
  131. if ($null -eq $value -or $value -eq '') {
  132. return $default
  133. }
  134. return $value
  135. }
  136. catch {
  137. return $default
  138. }
  139. }
  140.  
  141. # Function to format size
  142. function Format-Size {
  143. param([long]$Bytes)
  144.  
  145. if ($Bytes -eq 0) { return "0 B" }
  146.  
  147. $sizes = 'B','KB','MB','GB','TB'
  148. $order = [Math]::Floor([Math]::Log($Bytes, 1024))
  149. $num = [Math]::Round($Bytes / [Math]::Pow(1024, $order), 2)
  150.  
  151. return "{0:N2} {1}" -f $num, $sizes[$order]
  152. }
  153.  
  154. # Function to display detailed update information
  155. function Show-UpdateDetails {
  156. param($update)
  157.  
  158. if ($null -eq $update) {
  159. $infoTextBox.Text = "No update selected"
  160. return
  161. }
  162.  
  163. # Safely get properties
  164. $title = Get-SafeProperty $update 'Title'
  165. $kbArticles = if ($update.KBArticleIDs.Count -gt 0) { $update.KBArticleIDs -join ', ' } else { 'N/A' }
  166. $updateID = Get-SafeProperty $update.Identity 'UpdateID'
  167. $revision = Get-SafeProperty $update.Identity 'RevisionNumber'
  168. $size = Format-Size $update.MaxDownloadSize
  169. $categories = if ($update.Categories.Count -gt 0) {
  170. ($update.Categories | ForEach-Object { " - $($_.Name)" }) -join "`n"
  171. } else {
  172. ' N/A'
  173. }
  174. $severity = Get-SafeProperty $update 'MsrcSeverity'
  175. $description = Get-SafeProperty $update 'Description'
  176. $supportUrl = Get-SafeProperty $update 'SupportUrl'
  177. $moreInfo = if ($update.MoreInfoUrls.Count -gt 0) {
  178. $update.MoreInfoUrls -join "`n"
  179. } else {
  180. 'N/A'
  181. }
  182.  
  183. # Format dates safely
  184. $releaseDate = if ($update.ReleaseDate) {
  185. $update.ReleaseDate.ToString('yyyy-MM-dd HH:mm')
  186. } else {
  187. 'N/A'
  188. }
  189.  
  190. $lastChange = if ($update.LastDeploymentChangeTime) {
  191. $update.LastDeploymentChangeTime.ToString('yyyy-MM-dd HH:mm')
  192. } else {
  193. 'N/A'
  194. }
  195.  
  196. # Status flags
  197. $statusFlags = @()
  198. if ($update.IsHidden) { $statusFlags += 'Hidden' }
  199. if ($update.IsDownloaded) { $statusFlags += 'Downloaded' }
  200. if ($update.IsInstalled) { $statusFlags += 'Installed' }
  201. if ($update.IsMandatory) { $statusFlags += 'Mandatory' }
  202. if ($update.RebootRequired) { $statusFlags += 'Reboot Required' }
  203. if ($statusFlags.Count -eq 0) { $statusFlags += 'Visible, Not Downloaded' }
  204.  
  205. $details = @"
  206. UPDATE DETAILS
  207. $('=' * 40)
  208.  
  209. Title:
  210. $title
  211.  
  212. KB Article ID:
  213. $kbArticles
  214.  
  215. Update ID:
  216. $updateID
  217.  
  218. Revision:
  219. $revision
  220.  
  221. Size:
  222. $size
  223.  
  224. Categories:
  225. $categories
  226.  
  227. Severity:
  228. $severity
  229.  
  230. Status:
  231. $($statusFlags -join ', ')
  232.  
  233. Last Deployment Change:
  234. $lastChange
  235.  
  236. Release Date:
  237. $releaseDate
  238.  
  239. Support URL:
  240. $supportUrl
  241.  
  242. Description:
  243. $description
  244.  
  245. More Information:
  246. $moreInfo
  247. "@
  248.  
  249. $infoTextBox.Text = $details
  250. }
  251.  
  252. # ListView selection changed event
  253. $listView.Add_SelectedIndexChanged({
  254. if ($listView.SelectedItems.Count -gt 0) {
  255. $selectedItem = $listView.SelectedItems[0]
  256. $update = $selectedItem.Tag
  257. Show-UpdateDetails -update $update
  258.  
  259. # Also show brief info in details label
  260. $categoryNames = if ($update.Categories.Count -gt 0) {
  261. $update.Categories.Name -join ', '
  262. } else {
  263. 'N/A'
  264. }
  265.  
  266. $releaseInfo = if ($update.ReleaseDate) {
  267. "Release Date: $($update.ReleaseDate.ToShortDateString())"
  268. } else {
  269. "Release Date: N/A"
  270. }
  271.  
  272. $detailsLabel.Text = "Selected: $($update.Title)`n$releaseInfo | Categories: $categoryNames"
  273. }
  274. })
  275.  
  276. # Add tooltip functionality
  277. $tooltip = New-Object System.Windows.Forms.ToolTip
  278. $tooltip.AutoPopDelay = 10000
  279. $tooltip.InitialDelay = 500
  280. $tooltip.ReshowDelay = 100
  281.  
  282. # ListView mouse move event for tooltips
  283. $listView.Add_MouseMove({
  284. param($sender, $e)
  285.  
  286. $item = $listView.GetItemAt($e.X, $e.Y)
  287. if ($null -ne $item) {
  288. $update = $item.Tag
  289.  
  290. # Safely build tooltip text
  291. $kbText = if ($update.KBArticleIDs.Count -gt 0) {
  292. $update.KBArticleIDs -join ', '
  293. } else {
  294. 'N/A'
  295. }
  296.  
  297. $sizeText = Format-Size $update.MaxDownloadSize
  298. $severityText = Get-SafeProperty $update 'MsrcSeverity'
  299.  
  300. $releaseText = if ($update.ReleaseDate) {
  301. $update.ReleaseDate.ToShortDateString()
  302. } else {
  303. 'N/A'
  304. }
  305.  
  306. $tooltipText = @"
  307. $($update.Title)
  308. KB: $kbText
  309. Size: $sizeText
  310. Severity: $severityText
  311. Release: $releaseText
  312. "@
  313. $tooltip.SetToolTip($listView, $tooltipText)
  314. }
  315. })
  316.  
  317. # Scan button click event
  318. $scanButton.Add_Click({
  319. $listView.Items.Clear()
  320. $infoTextBox.Text = "Scanning..."
  321. $statusLabel.Text = 'Scanning for driver updates...'
  322. $progressBar.Visible = $true
  323. $scanButton.Enabled = $false
  324. $form.Refresh()
  325.  
  326. try {
  327. # Scan for all driver updates including hidden ones
  328. $updates = Get-WindowsUpdate -UpdateType Driver -WithHidden
  329.  
  330. foreach ($update in $updates) {
  331. $item = New-Object System.Windows.Forms.ListViewItem($update.Title)
  332.  
  333. # Get KB Article ID
  334. $kbArticle = if ($update.KBArticleIDs.Count -gt 0) {
  335. "KB" + $update.KBArticleIDs[0]
  336. } else {
  337. "N/A"
  338. }
  339. [void]$item.SubItems.Add($kbArticle)
  340.  
  341. # Format size
  342. $sizeText = Format-Size $update.MaxDownloadSize
  343. [void]$item.SubItems.Add($sizeText)
  344.  
  345. # Get status
  346. $status = if ($update.IsHidden) { "Hidden" } else { "Visible" }
  347. [void]$item.SubItems.Add($status)
  348.  
  349. # Get severity
  350. $severity = Get-SafeProperty $update 'MsrcSeverity'
  351. [void]$item.SubItems.Add($severity)
  352.  
  353. # Store the update object for later use
  354. $item.Tag = $update
  355. [void]$listView.Items.Add($item)
  356. }
  357.  
  358. $statusLabel.Text = "Found $($updates.Count) driver update(s)"
  359. $infoTextBox.Text = "Select an update to view details"
  360. }
  361. catch {
  362. [System.Windows.Forms.MessageBox]::Show("Error scanning for updates: $_", "Scan Error")
  363. $statusLabel.Text = "Error scanning for updates"
  364. $infoTextBox.Text = "Error: $_"
  365. }
  366.  
  367. $progressBar.Visible = $false
  368. $scanButton.Enabled = $true
  369. $hideButton.Enabled = $true
  370. $showButton.Enabled = $true
  371. $refreshButton.Enabled = $true
  372. })
  373.  
  374. # Hide button click event
  375. $hideButton.Add_Click({
  376. $selectedCount = 0
  377. $errorCount = 0
  378.  
  379. foreach ($item in $listView.CheckedItems) {
  380. $update = $item.Tag
  381. try {
  382. if ($update.KBArticleIDs.Count -gt 0) {
  383. Get-WindowsUpdate -KBArticleID $update.KBArticleIDs[0] -Hide -Confirm:$false | Out-Null
  384. } else {
  385. Hide-WindowsUpdate -Title $update.Title -Confirm:$false | Out-Null
  386. }
  387. $item.SubItems[3].Text = "Hidden"
  388. $update.IsHidden = $true
  389. $item.Checked = $false
  390. $selectedCount++
  391. }
  392. catch {
  393. $errorCount++
  394. }
  395. }
  396.  
  397. if ($errorCount -gt 0) {
  398. [System.Windows.Forms.MessageBox]::Show("Failed to hide $errorCount update(s). Make sure you're running as Administrator.", "Warning")
  399. }
  400.  
  401. $statusLabel.Text = "Hidden $selectedCount update(s)"
  402. })
  403.  
  404. # Show button click event
  405. $showButton.Add_Click({
  406. $selectedCount = 0
  407. $errorCount = 0
  408.  
  409. foreach ($item in $listView.CheckedItems) {
  410. $update = $item.Tag
  411. try {
  412. if ($update.KBArticleIDs.Count -gt 0) {
  413. Show-WindowsUpdate -KBArticleID $update.KBArticleIDs[0] -Confirm:$false | Out-Null
  414. } else {
  415. Get-WindowsUpdate -Title $update.Title -WithHidden -Hide:$false -Confirm:$false | Out-Null
  416. }
  417. $item.SubItems[3].Text = "Visible"
  418. $update.IsHidden = $false
  419. $item.Checked = $false
  420. $selectedCount++
  421. }
  422. catch {
  423. $errorCount++
  424. }
  425. }
  426.  
  427. if ($errorCount -gt 0) {
  428. [System.Windows.Forms.MessageBox]::Show("Failed to show $errorCount update(s). Make sure you're running as Administrator.", "Warning")
  429. }
  430.  
  431. $statusLabel.Text = "Unhidden $selectedCount update(s)"
  432. })
  433.  
  434. # Refresh button click event
  435. $refreshButton.Add_Click({
  436. if ($listView.SelectedItems.Count -gt 0) {
  437. $selectedItem = $listView.SelectedItems[0]
  438. $update = $selectedItem.Tag
  439. Show-UpdateDetails -update $update
  440. }
  441. })
  442.  
  443. # Show the form
  444. [void]$form.ShowDialog()
  445.  
Tags: WUShowHide
Advertisement
Add Comment
Please, Sign In to add comment