locked
WSUS Powershell Report RRS feed

  • Question

  • Hi There,

    i am trying to create a custom report on wsus using powershell. below code i got it from one of the technet forum . I am trying to modify this to add few mode details like patch Creation date , Arrival Date , ProductTitles of patch etc.. 

    The Script works fine except getting the ProductTitles for the patches. The output for product titles will be "System.Collections.Specialized.StringCollection"

    Below is the code i am using.


    ##### Connect to WSUS ##################

    $wsusserver = "192.168.10.10"
    $Port = 8530
    $UseSSL = $False

    [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")

    $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($wsusserver,$UseSSL,$Port)

    #################################################################
    $TargetGroup = 'Web_Portals'
    $updateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
    $updateScope.IncludedInstallationStates = 'Downloaded','NotInstalled','InstalledPendingReboot'


    $output = ($wsus.GetComputerTargetGroups() | Where {$_.Name -eq $TargetGroup}).GetComputerTargets() | ForEach {
            $Computername = $_.fulldomainname
    $IPAddress = $_.IPAddress
            $_.GetUpdateInstallationInfoPerUpdate($updateScope) | ForEach {
                $update = $_.GetUpdate()
    [pscustomobject]@{
                    Computername = $Computername
    IPAddress = $IPAddress
                    TargetGroup = $TargetGroup
                    UpdateTitle = $Update.Title
    KB = "KB"+($update.KnowledgebaseArticles)
    IsApproved = $update.IsApproved
    Creationdate = $update.Creationdate.ToString("yyyy-MM-dd")
    ArrivalDate = $update.ArrivalDate.ToString("yyyy-MM-dd")
    ProductTitles = $update.ProductTitles
                }
        }
    }

    $output | ConvertTo-Csv >C:\Scripts\HotfixList\wsuspatch_reports.csv

    ######TRIM First Line of CSV Output ################

    (Get-Content "C:\Scripts\HotfixList\wsuspatch_reports.csv" | Select-Object -Skip 1) | Set-Content "C:\Scripts\HotfixList\wsuspatch_reports.csv"

    ################################################################

    Please help in resolving this.

    Wednesday, October 17, 2018 12:39 PM

Answers

  • ProductTitles = %{$update.ProductTitles}

    or try

    ProductTitles = $update.ProductTitles.tostring()



    • Edited by Jon.Knight Wednesday, October 17, 2018 12:45 PM
    • Marked as answer by IBS Sol_DC Wednesday, October 17, 2018 1:14 PM
    Wednesday, October 17, 2018 12:44 PM
  • ProductTitles = %{$update.ProductTitles} | ?{$_ -like "*2012*"}
    • Marked as answer by IBS Sol_DC Wednesday, October 17, 2018 2:32 PM
    Wednesday, October 17, 2018 1:24 PM

All replies

  • ProductTitles = %{$update.ProductTitles}

    or try

    ProductTitles = $update.ProductTitles.tostring()



    • Edited by Jon.Knight Wednesday, October 17, 2018 12:45 PM
    • Marked as answer by IBS Sol_DC Wednesday, October 17, 2018 1:14 PM
    Wednesday, October 17, 2018 12:44 PM
  • Many Thanks Jon , that works fine when i use 

    ProductTitles = %{$update.ProductTitles}

    For some patches like Microsoft .NET Framework 4.7 for Windows 8.1 and Windows Server 2012 R2 for x64 (KB3186539)

    it still gives System.Object[] 

    I believe its because this is applicable to both windows 8 and 2012 R2 . Can we try to do some pattern matching on the  UpdateTitle = $Update.Title output which has these OS versions and display it as product Titles.


    Wednesday, October 17, 2018 1:13 PM
  • ProductTitles = %{$update.ProductTitles} | ?{$_ -like "*2012*"}
    • Marked as answer by IBS Sol_DC Wednesday, October 17, 2018 2:32 PM
    Wednesday, October 17, 2018 1:24 PM
  • Perfect , that works like a charm

    Since we have multiple server OS , line server 2012 and Server 2008 etc i have given match word as "Server"

    ProductTitles = %{$update.ProductTitles} | ?{$_ -like "*Server*"}

    Thank you Very Much Jon

    Wednesday, October 17, 2018 2:32 PM