locked
WSUS Powershell RRS feed

  • Question

  • Hello,

    I have copied this script to decline specific updates in WSUS

    https://community.spiceworks.com/scripts/show/2795-decline-wsus-updates

    On the original script there is a line which is, this then searches for Itanium updates which are not declined already and then will decline them. 

    $itanium = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match “itanium”}

    Whilst the above works perfectly I need to keep a record of exactly which updates are being declined into a CSV, so I added the following

    $itanium = $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match “itanium”} | select title | export-csv S:\WSUSDeclinedUpdates\Sharepoint\$(get-date -format dd_MM_yy)-DeclinedSharepointUpdates.csv
    $sharepoint_counted = $sharepoint.count

    I then get a CSV which has the title and saves into the CSV however the update doesn't decline! If I remove the | select........... then it will decline.

    There are no errors present, so is it something wrong with the piping?

    Wednesday, October 18, 2017 1:40 PM

Answers

  • You can also do:
    $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match 'itanium'} | Foreach-Object {
    # 1. decline
    $_.Decline()
    # 2. send back the update through the pipeline
    $_ 
    } | select Title | export-csv S:\WSUSDeclinedUpdates\Sharepoint\$(get-date -format dd_MM_yy)-DeclinedSharepointUpdates.csv

    • Marked as answer by mikemyres Thursday, October 19, 2017 8:08 AM
    Wednesday, October 18, 2017 3:42 PM

All replies

  • Hi,

    To decline an update, you need to call the Decline() method on this update.

    Typically, you'll need to do:

     $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match 'itanium'} | Foreach-Object {
    # 1. decline
    $_.Decline()
    # 2. send back the title through the pipeline
    $_.Title 
    } | export-csv S:\WSUSDeclinedUpdates\Sharepoint\$(get-date -format dd_MM_yy)-DeclinedSharepointUpdates.csv

    Wednesday, October 18, 2017 2:29 PM
  • Hi,

    That's almost done the trick but the CSV just has 106 in the file, doesn't have the title of the update name.

    I tried adding | select title before | export-csv on what you posted however that made no difference

    as I just got 

    #TYPE Selected.System.String
    "title"

    back in the csv

    Wednesday, October 18, 2017 3:28 PM
  • You can also do:
    $WsusServerAdminProxy.GetUpdates() | ?{-not $_.IsDeclined -and $_.Title -match 'itanium'} | Foreach-Object {
    # 1. decline
    $_.Decline()
    # 2. send back the update through the pipeline
    $_ 
    } | select Title | export-csv S:\WSUSDeclinedUpdates\Sharepoint\$(get-date -format dd_MM_yy)-DeclinedSharepointUpdates.csv

    • Marked as answer by mikemyres Thursday, October 19, 2017 8:08 AM
    Wednesday, October 18, 2017 3:42 PM
  • Perfect! 
    Many thanks

    Thursday, October 19, 2017 8:08 AM