0
$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()

$historyCount = $Searcher.GetTotalHistoryCount()

$a=$Searcher.QueryHistory(0, $historyCount) | Select-Object Title 

$a

Request you to kindly help me to filter only KBxxxx,softwarenamelist for the above command output.

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
hasini
  • 7
  • 7
  • 1
    What is `softwarenamelist`? – henrycarteruk Oct 16 '17 at 10:37
  • Thank you for your kind response. James C "Update for Microsoft Word 2013 (KB4011045) 64-Bit Edition" result of the above command i need to get format as "KB4011045","Update for Microsoft Word 2013 (KB4011045) 64-Bit Edition" Request you to kindly suggest. – hasini Oct 16 '17 at 10:44

2 Answers2

0

You could try this at the end of your own code :

$arrayKb = @()

foreach($strKb in $a){
    $strKb -match "KB\d{7}"
    $kb = $Matches[0]

    $itemObject = New-Object System.Object
    $itemObject | Add-Member -type NoteProperty -Name "Kb" -Value $kb
    $itemObject | Add-Member -type NoteProperty -Name "Software" -Value $strKb
    $arrayKb += $itemObject
}

$arrayKb
Manu
  • 1,685
  • 11
  • 27
0

Using this RegEx to capture the KB Number from between the parentheses, and then Calculated Properties to make it neat:

$a = $Searcher.QueryHistory(0, $historyCount) | Select-Object @{Name="KB";Expression={[regex]::match($_.Title,'\(([^\)]+)\)').Groups[1].Value}},@{Name="Title";Expression={$_.Title}}
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • Its working fine Thank you very much. how can we format this expression including double quotes ""KB4011045","Update for Microsoft Word 2013 64-Bit Edition" and remove unwanted space between 2 columns and KBxxxxx details need to be hided in title list. – hasini Oct 17 '17 at 01:31
  • $a = $Searcher.QueryHistory(0, $historyCount) | Select-Object @{Name="KB";Expression={'"'+[regex]::match($_.Title,'\(([^\)]+)\)').Groups[1].Value+'"'}}, @{Name="Title";Expression={','+'"'+$_.Title +'"'}} i have added quotes and command as per the above code but how to remove the unwanted space between KB&title i would like to get the output format as "KB4011045","Update for Microsoft Word 2013 64-Bit Edition" but i am managed to get "KB4011045" ,"Update for Microsoft Word 2013 (KB4011045) 64-Bit Edition" i want to remove the unwanted space between kb and namelist.please. – hasini Oct 17 '17 at 04:36
  • i have rectified the space issue, request you to kindly guide me to hide Update for Microsoft Word 2013 (KB4011045) 64-Bit Edition in this i would to see only Update for Microsoft Word 2013 64-Bit Edition how to hide the KBXXXX using regex – hasini Oct 17 '17 at 05:00