locked
Export to CSV RRS feed

  • Question

  • Hi,

    How would I export the output from the below command to .CSV?

    $UpdateSession = New-Object -ComObject Microsoft.Update.Session
    $SearchResult = $null
    $UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
    $UpdateSearcher.Online = $true
    $SearchResult = $UpdateSearcher.Search("IsInstalled=1 and Type='Software'")

    $i = 1
    foreach($Update in $SearchResult.Updates)
    {
     Write-Host "$i) $($Update.Title + " | " + $Update.SecurityBulletinIDs)"
     $i += 1
    }

    Monday, February 5, 2018 11:29 AM

Answers

  • You could do something like the following and put it in a custom table then export the results

    $resultsarray =@()
    $UpdateSession = New-Object -ComObject Microsoft.Update.Session 
    $SearchResult = $null
    $UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
    $UpdateSearcher.Online = $true
    $SearchResult = $UpdateSearcher.Search("IsInstalled=1 and Type='Software'") 
    
    $i = 1
    
    foreach($Update in $SearchResult.Updates)
     {
      
        $Obj = New-Object PSObject
        $Obj | Add-Member -type NoteProperty -name "Title" -Value "$i) $($Update.Title + " | " + $Update.SecurityBulletinIDs)"
        $resultsarray +=  $Obj
        $i += 1
    
     }
     $resultsarray | Export-Csv "C:\temp\Results.csv" -NoTypeInformation

    • Proposed as answer by Udit Daga Monday, February 5, 2018 11:54 AM
    • Marked as answer by Blue_man2 Friday, April 20, 2018 10:09 PM
    Monday, February 5, 2018 11:44 AM

All replies

  • You could do something like the following and put it in a custom table then export the results

    $resultsarray =@()
    $UpdateSession = New-Object -ComObject Microsoft.Update.Session 
    $SearchResult = $null
    $UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
    $UpdateSearcher.Online = $true
    $SearchResult = $UpdateSearcher.Search("IsInstalled=1 and Type='Software'") 
    
    $i = 1
    
    foreach($Update in $SearchResult.Updates)
     {
      
        $Obj = New-Object PSObject
        $Obj | Add-Member -type NoteProperty -name "Title" -Value "$i) $($Update.Title + " | " + $Update.SecurityBulletinIDs)"
        $resultsarray +=  $Obj
        $i += 1
    
     }
     $resultsarray | Export-Csv "C:\temp\Results.csv" -NoTypeInformation

    • Proposed as answer by Udit Daga Monday, February 5, 2018 11:54 AM
    • Marked as answer by Blue_man2 Friday, April 20, 2018 10:09 PM
    Monday, February 5, 2018 11:44 AM
  • Hello,

    since you have an object already:

    $SearchResult | select Title, SecurityBulletinIDs | Export-CSV "YourPath.csv" -delimiter ";" -noTypeInformation

    Monday, February 5, 2018 11:54 AM
  • Did you try running that?

    Brings back nothing.

    Monday, February 5, 2018 12:03 PM
  • Start with this:

    $UpdateSession = New-Object -ComObject Microsoft.Update.Session 
    $UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
    $SearchResult = $UpdateSearcher.Search("IsInstalled=1 and Type='Software'")
    $SearchResult.Updates | Export-Csv updates.csv


    \_(ツ)_/

    Monday, February 5, 2018 6:44 PM
  • No, I was not running that. But I simply missed .Updates.

    $SearchResult.Updates | select Title, SecurityBulletinIDs | Export-CSV "YourPath.csv" -delimiter ";" -noTypeInformation


    Tuesday, February 6, 2018 9:22 AM
  • You cannot get "SecurityBulletinIDs" this way.  They must be "Invoked".

    find-Module PsWindowsUpdate | Install-Module


    \_(ツ)_/

    Tuesday, February 6, 2018 9:43 AM