locked
WSUS Custom Powershell Reports RRS feed

  • General discussion

  • 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.



    • Edited by IBS Sol_DC Wednesday, October 17, 2018 11:30 AM
    • Changed type IBS Sol_DC Wednesday, October 17, 2018 2:36 PM
    Wednesday, October 17, 2018 11:26 AM

All replies

  • This is Answered in another thread .

    Re-posting the answers below.

    ProductTitles = $update.ProductTitles.tostring()

     or 

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

    https://social.technet.microsoft.com/Forums/en-US/b500b74b-f950-4df0-83ac-db6a9e8bfbf4/wsus-powershell-report?forum=winserverpowershell

    Wednesday, October 17, 2018 2:35 PM
  • Hi,

    Thanks for sharing the information here. It is useful for us to use the power shell scripts to view the specify informaiton of the updates. 

    Best regards,
    Johnson
    =====================
    Please remember to mark the replies as answers if they help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
    Thursday, October 18, 2018 2:03 AM