I want to get all of this information (including non-windows updates) in any text format... Please share if you have any way to fetch these infos. For more details please see attached image...
Edit:
To get all the updates (installed via Windows Update only, even for 3rd party) and then export the result to a text file, you can use below script:
$session = [activator]::CreateInstance([type]::GetTypeFromProgID(“Microsoft.Update.Session”,$ComputerName))
$us = $session.CreateUpdateSearcher()
$qtd = $us.GetTotalHistoryCount()
$hot = $us.QueryHistory(0, $qtd)
# Output object
$OutPut = @()
#Iterating and finding updates
foreach ($Upd in $hot) {
# 1 means in progress and 2 means succeeded
if ($Upd.operation -eq 1 -and $Upd.resultcode -eq 2) {
$OutPut += New-Object -Type PSObject -Prop @{
‘ComputerName’=$computername
‘UpdateDate’=$Upd.date
‘KB’=[regex]::match($Upd.Title,’KB(\d+)’)
‘UpdateTitle’=$Upd.title
‘UpdateDescription’=$Upd.Description
‘SupportUrl’=$Upd.SupportUrl
‘UpdateId’=$Upd.UpdateIdentity.UpdateId
‘RevisionNumber’=$Upd.UpdateIdentity.RevisionNumber
}
}
}
#Writing updates to a text file
$OutPut | Out-File -FilePath "C:\output.txt" -Append
Older Response:
Instead of creating your own script you can use this wonderful script from Technet: PowerShell script to list all installed Microsoft Windows Updates
As you want the output in text format, I have updated the script from that article to generate output for all the installed updates in a text file. Everything is configurable. Check the complete script below. The last line is where I am invoking the reusable method and generating the output into a text file. You can change the path to this text file as per your environment.
Function Get-MSHotfix
{
$outputs = Invoke-Expression "wmic qfe list"
$outputs = $outputs[1..($outputs.length)]
foreach ($output in $Outputs) {
if ($output) {
$output = $output -replace 'y U','y-U'
$output = $output -replace 'NT A','NT-A'
$output = $output -replace '\s+',' '
$parts = $output -split ' '
if ($parts[5] -like "*/*/*") {
$Dateis = [datetime]::ParseExact($parts[5], '%M/%d/yyyy',[Globalization.cultureinfo]::GetCultureInfo("en-US").DateTimeFormat)
} elseif (($parts[5] -eq $null) -or ($parts[5] -eq ''))
{
$Dateis = [datetime]1700
}
else {
$Dateis = get-date([DateTime][Convert]::ToInt64("$parts[5]", 16))-Format '%M/%d/yyyy'
}
New-Object -Type PSObject -Property @{
KBArticle = [string]$parts[0]
Computername = [string]$parts[1]
Description = [string]$parts[2]
FixComments = [string]$parts[6]
HotFixID = [string]$parts[3]
InstalledOn = Get-Date($Dateis)-format "dddd d MMMM yyyy"
InstalledBy = [string]$parts[4]
InstallDate = [string]$parts[7]
Name = [string]$parts[8]
ServicePackInEffect = [string]$parts[9]
Status = [string]$parts[10]
}
}
}
}
Get-MSHotfix|Select-Object -Property Computername, KBArticle,InstalledOn, HotFixID, InstalledBy|Format-Table | Out-File -FilePath "D:\output.txt"