LIST INSTALLED UPDATES

karlsnooks

Windows Specialist
Joined
May 31, 2012
Posts
94
Following powershell script will put InstalledUpdates.txt on your DESKTOP screen which has date, name, and description of your installed updates.

PHP:
# Places INSTALLEDUPDATES.TXT on your DESKTOP screen
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(1,$HistoryCount) | 
Select-Object Date, Title, Description | 
fl > $env:userprofile\desktop\InstalledUpdates.txt

EXIT
EXIT

To run a powershell script, please see:
https://www.sysnative.com/forums/showthread.php/4022-HOW-TO-RUN-A-POWERSHELL-SCRIPT
 
Following powershell script will put InstalledUpdates.txt on your DESKTOP screen which has date, name, and description of your installed updates.

PHP:
# Places INSTALLEDUPDATES.TXT on your DESKTOP screen
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(1,$HistoryCount) | 
Select-Object Date, Title, Description | 
fl > $env:userprofile\desktop\InstalledUpdates.txt

EXIT
EXIT

To run a powershell script, please see:
https://www.sysnative.com/forums/showthread.php/4022-HOW-TO-RUN-A-POWERSHELL-SCRIPT

This script won't work, and you don't need 2 'EXIT's at the end though.

You're forgetting '\'s in the path as well:
Code:
$env:userprofile\Desktop\InstalledUpdates.txt

$env:userprofiledesktopInstalledUpdates.txt doesn't exist

Try this:
Code:
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$f = $env:USERPROFILE+'\Desktop\updates.txt'

foreach ($obj in $Searcher.QueryHistory(1,$HistoryCount))
{
	$obj.Title >> $f
	$obj.Descriptiont >> $f
	$obj.Date + '-------------------------------`n' >> $f
}

With that, I can get something like this output:
Code:
Security Update for Microsoft SharePoint Workspace 2010 (KB2566445), 64-Bit Edition
A security vulnerability exists in Microsoft SharePoint Workspace 2010, 64-Bit Edition that could allow arbitrary code to run when a maliciously modified file is opened. This update resolves that vulnerability.

Thursday, March 01, 2012 1:58:16 AM
-----------------------------------------
Security Update for Microsoft .NET Framework 4 on XP, Server 2003, Vista, Windows 7, Server 2008, Server 2008 R2 for x64 (KB2572078)
A security issue has been identified that could allow an unauthenticated remote attacker to compromise your system and gain control over it. You can help protect your system by installing this update from Microsoft. After you install this update, you may have to restart your system.

Thursday, March 01, 2012 1:57:25 AM
-----------------------------------------
Update for Microsoft Office 2010 (KB2553310) 64-Bit Edition
Microsoft has released an update for Microsoft Office 2010 64-Bit Edition. This update provides the latest fixes to Microsoft Office 2010 64-Bit Edition. Additionally, this update contains stability and performance improvements.

Thursday, March 01, 2012 1:55:00 AM
 
Last edited:
Following powershell script will put InstalledUpdates.txt on your DESKTOP screen which has date, name, and description of your installed updates.

This script won't work, and you don't need 2 'EXIT's at the end though.
2 EXITS REQUIRED IN SOME CASES. Depends upon how one does the copy and paste. I've been doing this for awhile and have learned that the path of least resistance was to include the both. Saved me explanations later.

You're forgetting '\'s in the path as well:

Don't know what happened to the "\". They are in my original. I always test drive a script before posting. Perhaps a peculiarity of the forum software.

I'll run down the source of the missing backslashes. Here is a sample of what I got on my desktop:

Date : 08-Oct-12 20:26:56
Title : Definition Update for Windows Defender - KB2267602 (Definition 1.137.1316.0)
Description : Install this update to revise the definition files that are used to detect viruses, spyware, and other potentially unwanted software. Once you have installed this item, it cannot be
removed.

----------------------------
thanks and now I'll try to find out why. Just checked the script on my skydrive site is correct.
Will now try to run down a couple of other possibilities,
karl
 
a Feature of this forum's implementation.

I tried double backslashes and that didn't work. Will try quoting the backslash.
Nope. Didn't work.

Who knows the answer?
 
Am going to try a script with some spacing,not extensive, but I'll copy and paste into a CODE box to see if code box works with no problems.

Code:
# ************************************************************
# Puts DISKINFO.TXT on your Desktop.
# contains info about your disks, partitions, and volumes
# ************************************************************

function get-ID { 
  param ([string]$title, [int]$arraycnt, [int]$arrayndx) 
  $id = " " + $title + " "
  If ($arraycnt -ne 1) {$id = $id + [string]$arrayndx + " "}
  $id }
function get-title { param ([string]$id) 
  $hashes = ([int](51 - $id.length)/2)
  $hashstr = '#' * $hashes
  $title = $hashstr + $id + $hashstr
  If ($title.length -le 51) {$title += "#"}
  $title  }
$sterne = "*" * 79
$obj = New-Object PSObject

$dskarr =@(gwmi win32_diskdrive)
$cnt = $dskarr.count
for($ndx=1; $ndx -le $cnt; $ndx++) {
  $d = $dskarr[$ndx -1];
  $id = get-id "DISK" $cnt $ndx
  $obj | Add-member -membertype noteproperty -name (get-title $id) -value $sterne
  $obj | add-member -membertype noteproperty -name ($id + "Model") -value($d.model)
  $obj | add-member -membertype noteproperty -name ($id + "Size") -value([string][int]($d.size/1073741824) + " GB")
  $obj | add-member -membertype noteproperty -name ($id + "Status") -value($d.status)
  $obj | add-member -membertype noteproperty -name ($id + "Capabilities") -value($d.capabilitydescriptions)
  $obj | add-member -membertype noteproperty -name ($id + "Interface Type") -value($d.interfacetype)
  $obj | add-member -membertype noteproperty -name ($id + "Partitions") -value($d.partitions)
  $obj | add-member -membertype noteproperty -name ($id + "Bytespersector") -value($d.bytespersector)
  $obj | add-member -membertype noteproperty -name ($id + "Sectors per track") -value($d.sectorspertrack)
  $obj | add-member -membertype noteproperty -name ($id + "Firmware revision") -value($d.firmwarerevision)
  $obj | add-member -membertype noteproperty -name ($id + "Device ID") -value($d.deviceid)
  $obj | add-member -membertype noteproperty -name ($id + "PNP Device ID") -value($d.pnpdeviceid)
}
$dsk =@(gwmi win32_LogicalDisk)
$cnt = $dsk.count
for($ndx=1; $ndx -le $cnt; $ndx++){
  $d = $dsk[$ndx-1];
  $id = get-id "LOGICAL DISK" $cnt $ndx
  $obj | add-member -membertype noteproperty -name (get-title $id)  -value $sterne
  $obj | add-member -membertype noteproperty -name ($id + "Caption") -value($d.caption)
  $obj | add-member -membertype noteproperty -name ($id + "Volume Name") -value($d.volumename)
  $obj | add-member -membertype noteproperty -name ($id + "Description") -value($d.description)
  $obj | add-member -membertype noteproperty -name ($id + "Size") -value([string][int]($d.size/1073741824) + " GB")
  $obj | add-member -membertype noteproperty -name ($id + "Used Space") -value ([string][int](($d.size - $d.freespace)/1073741824) + " GB")
  $obj | add-member -membertype noteproperty -name ($id + "Free Space") -value([string][int]($d.freespace/1073741824) + " GB")
  $obj | add-member -membertype noteproperty -name ($id + "File System") -value($d.filesystem)
  $obj | add-member -membertype noteproperty -name ($id + "Compressed") -value($d.compressed)
  $obj | add-member -membertype noteproperty -name ($id + "Volume Dirty") -value($d.volumedirty)
  $obj | add-member -membertype noteproperty -name ($id + "Volume Serial Number") -value($d.volumeserialnumber)
}
$dsk =@(gwmi win32_diskpartition)
$cnt = $dsk.count
for($ndx=1; $ndx -le $cnt; $ndx++){
  $d = $dsk[$ndx-1];
  $id = get-id "DISK PARTITION" $cnt $ndx
  $obj | add-member -membertype noteproperty -name (GET-title $id)  -value $sterne
  $obj | add-member -membertype noteproperty -name ($id + "Caption") -value($d.caption)
  $obj | add-member -membertype noteproperty -name ($id + "Size") -value([string][int]($d.size/1073741824) + " GB")
  $obj | add-member -membertype noteproperty -name ($id + "Primary Partition") -value($d.primarypartition)
  $obj | add-member -membertype noteproperty -name ($id + "Boot Partition") -value($d.bootpartition)
  $obj | add-member -membertype noteproperty -name ($id + "Bootable") -value($d.bootable)
  $obj | add-member -membertype noteproperty -name ($id + "Block Size") -value($d.blocksize)
  $obj | add-member -membertype noteproperty -name ($id + "Number of Blocks") -value($d.numberofblocks)
  $obj | add-member -membertype noteproperty -name ($id + "Starting Offset") -value($d.startingoffset)
}
function Get-DrvType ($n) {
  switch ([int]$n) {
   2  {$result = "Removable"}
   3  {$result = "Partition"}
   5  {$result = "CDROM"}
   default {$result = "Unknown"}
   } 
  $result
}
$dsk = @(gwmi win32_volume)
$cnt = $dsk.count
for ($ndx=1; $ndx -le $cnt; $ndx++) {
  $d = $dsk[$ndx-1]
  $id = get-id "DISK VOLUME" $cnt $ndx
  $obj | add-member -membertype noteproperty -name (get-title $id)  -value $sterne
  $obj | add-member -membertype noteproperty -name ($id + "Caption") -value($d.caption)
  $obj | add-member -membertype noteproperty -name ($id + "Drive Letter") -value($d.driveletter)
  $obj | add-member -membertype noteproperty -name ($id + "Label") -value($d.label)
  $obj | add-member -membertype noteproperty -name ($id + "Capacity") -value([string][int]($d.capacity/1073741824) + " GB")
  $obj | add-member -membertype noteproperty -name ($id + "Free Space") -value([string][int]($d.freespace/1073741824) + " GB")
  $obj | add-member -membertype noteproperty -name ($id + "Volume Type") -value(get-drvtype($d.drivetype))
  $obj | add-member -membertype noteproperty -name ($id + "Boot Volume") -value($d.bootvolume)
  $obj | add-member -membertype noteproperty -name ($id + "System Volume") -value($d.systemvolume)
  $obj | add-member -membertype noteproperty -name ($id + "Compressed") -value($d.compressed)
  $obj | add-member -membertype noteproperty -name ($id + "Serial Number") -value($d.serialnumber)
  $obj | add-member -membertype noteproperty -name ($id + "File System") -value($d.filesystem)
  $obj | add-member -membertype noteproperty -name ($id + "Block Size") -value($d.blocksize)
  $obj | add-member -membertype noteproperty -name ($id + "Indexing Enabled") -value($d.indexingenabled)
  $obj | add-member -membertype noteproperty -name ($id + "Auto Mount") -value($d.automount)
  $obj | add-member -membertype noteproperty -name ($id + "Dirty Bit Set") -value($d.dirtybitset)
}

$obj > $env:userprofile\desktop\DISKINFO.TXT

EXIT
EXIT

# ************************************************************
 
Code block is working correctly.

Any suggestions on selecting the contents of a code block for pasting purposes in an easy manner?

The Ctrl+A approach selected the entire post even with pointer inside the block..
 
Code block is working correctly.

Any suggestions on selecting the contents of a code block for pasting purposes in an easy manner?

The Ctrl+A approach selected the entire post even with pointer inside the block..

This is a general tip which applies to almost anywhere in Windows.

Single click just before the first character you wish to select, scroll or slide down to bottom of code box, and Shift+click just after last character you wish to select.

Now use Ctrl-C or right click > Copy.
 
OK for the poor souls who made it down this far:

Code:
# Places INSTALLEDUPDATES.TXT on your DESKTOP screen
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(1,$HistoryCount) | 
Select-Object Date, Title, Description | 
fl > $env:userprofile\desktop\InstalledUpdates.txt

EXIT
EXIT
 
Richard,
I have tried that but my old fingers aren't as nimble and I went sailing by the end of the script.
Had to shift backarrow to clean up the selection.

I may go back to never pasting a script in a post and always referencing link to a .txt or .ps1 file.

I'm looking for the easiest approach with the least problems when dealing with the non-computer savvy which is the vast majority of the Windows users.

Oh yes, on short scripts that approach generally works fine.
 
You originally had a PHP code tag, backslashes worked for me in the [ code = powershell ] tag. Again though--this part isn't really necessary:
Code:
EXIT
EXIT

You don't need even 1 of those, because it's the end of the script, it'll terminate on it's own. Exit just closes the powershell window, so that may not be what you want anyways, especially if you're running this through the command line ".\script.ps1". Otherwise, running by clicking the ps1 file, and it'll close on it's own anyways. So it's really not necessary.
 
I have found that some will only copy thru but not past an EXIT statement.
I solve this problem by including two EXIT statements.

This is not a problem with PS but rather a characteristic of some users.

I'm well aware of PS features.
thanks,
karl
 
I have found that some will only copy thru but not past an EXIT statement.
I solve this problem by including two EXIT statements.

This is not a problem with PS but rather a characteristic of some users.

I'm well aware of PS features.
thanks,
karl

Well... In my opinion, since I can see both (without scrolling) and the fact that they are both in all caps, I think it's misleading to those inspiring programmers wanting to learn Powershell lol. I don't see how anybody could miss that, however, treating them like children in the event that they can't copy and paste the full thing is not the solution. But if you insist..
 
Although WMI does work, it's actually slower from what i've seen in comparison to other methods and function calls. Not sure about Powershell though in comparison to that WMI query. Could do a benchmark test I guess. :)
 
I also have a script using WMI, but I've found this one to be faster and adequate for most cases.

Want to see the hot-fixes?
Get-HotFix -Description Update | ft -auto -wrap
 
No argument here that WMI is not as fast as what you guys are writing, but I am unfamiliar with your languages (I can help you with a tax audit or in tax court, though! :lol: )

I developed the jcgriff2 BSOD File collection app starting in 2008 and does include some WMI. No doubt in my mind that the run time could be cut greatly if re-coded. However, not a whole lot can be done with Windows executables like msinfo32, which seems to take the longest to run.

My apps (batch, VBS, WMI) are geared toward gathering system info from OPs.

~70 WMI apps are attached to this post --> https://www.sysnative.com/forums/sh...-Instrumentation?p=24078&viewfull=1#post24078

I test them, but rarely ever run them on my own systems.
 
I agree and I admire the work that you've done.

Win 3.0 is going to spoil me:
get-service | where status -match 'Running' |select name, status | ft -auto
 
I also have a script using WMI, but I've found this one to be faster and adequate for most cases.

Want to see the hot-fixes?
Get-HotFix -Description Update | ft -auto -wrap

Most of those though are just default powershell cmdlets. And you can format and sort however you want by piping the output to some kind of formatting object. I like seeing the scripts that do much more than this though. (Having a hard time putting this in a considerate way)

Scripts that would've taken a bit more time to write out.

I seen the same thing with Batch. Everybody gets excited at first when they finally start scripting in a new language, but doing all the same stuff over and over (like batch and echo, deleting files, making cool batch menus, etc...) gets boring. Don't take that wrongly... I'd be glad to show you a few scripts that i've created to show you what I mean :)

Being a powershell enthusiast, I think it's much better than batch. It can also utilize .NET methods, which is a bonus. Try fooling around with that stuff :)
 
Last edited:

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top