query WSUS

query WSUS

Postby anienigma » 02.01.2018, 15:17

In case anyone was interested on a possible integration technique please consider the following to gather local approved patches from a WSUS, and then use the FAQ to integrate these into wsusoffline. You will need to replace <> with the data its asking for.

Code: Select all
#Function to gather all propery information for local WSUS packages
function Get-PSWSUSUpdateFile {
    [cmdletbinding(
       DefaultParameterSetName = 'Name'
    )]
    Param(
        [Parameter(           
            Mandatory = $False,
            Position = 0,
            ParameterSetName = 'object',
            ValueFromPipeline = $True)]
            [system.object]
            [ValidateNotNullOrEmpty()]
            $InputObject,     
        [Parameter(
            Mandatory = $False,
            Position = 0,
            ParameterSetName = 'Name',
            ValueFromPipeline = $True)]
            [string]$UpdateName                               
        )
    Process {
        #Perform appropriate action based on Parameter set name
        Switch ($pscmdlet.ParameterSetName) {           
            "object" {
                Write-Verbose "Using 'Collection' set name"
                #Change the variable that will hold the objects
                If ($InputObject -is [Microsoft.UpdateServices.Internal.BaseApi.Update]) {
                    $Items = $InputObject | ForEach {
                        $data = $_.GetInstallableItems() | Add-Member -MemberType NoteProperty -Name KnowledgeBaseArticles -value $_.KnowledgeBaseArticles -PassThru
                        $data | Add-Member -MemberType NoteProperty -Name Title -value $_.Title -PassThru
                    }
                } ElseIf ($InputObject -is [Microsoft.UpdateServices.Internal.BaseApi.InstallableItem]) {
                    $Items = $InputObject
                }
            }
            "name" {
            #Sets the local WSUS instance (required)
            $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer()
                if($wsus)
                {
                    Write-Verbose "Using 'Update Name' set name"
                    #Search for updates
                    Write-Verbose "Searching for update/s"
                    $patches = @($wsus.SearchUpdates($UpdateName))
                    If ($patches -eq 0) {
                        Write-Error "Update $update could not be found in WSUS!"
                        Break
                    } Else {
                        $Items = $patches | ForEach {
                            $Patch = $_
                            Write-Verbose ("Adding NoteProperty for {0}" -f $_.Title)                   
                            $_.GetInstallableItems() | ForEach {
                                $itemdata = $_ | Add-Member -MemberType NoteProperty -Name KnowledgeBaseArticles -value $patch.KnowledgeBaseArticles -PassThru
                                $itemdata | Add-Member -MemberType NoteProperty -Name Title -value $patch.Title -PassThru
                            }
                        }
                    }
                }
            }
        }
      #Gathers title information
        ForEach ($item in $items) {
            Write-Verbose ("Getting installable items on {0}" -f $item.Title)
            Try {
                $filedata = $item | Select -Expand Files | Add-Member -MemberType NoteProperty -Name KnowledgeBaseArticles -value $item.KnowledgeBaseArticles -PassThru
                $filedata | Add-Member -MemberType NoteProperty -Name Title -value $item.Title -PassThru
            } Catch {
                Write-Warning ("{0}: {1}" -f $item.id.id,$_.Exception.Message)
            }
        }
    }
}

#Collect the appoved SQL patches, for 2012/2014/2016, from the local WSUS
$updatelist2012 = Get-WSUSUpdate -Approval Approved -Status Any | Where-Object {$_.Update.title -like "*sql*" -and $_.Update.title -like "*2012*"}
$updatelist2014 = Get-WSUSUpdate -Approval Approved -Status Any | Where-Object {$_.Update.title -like "*sql*" -and $_.Update.title -like "*2014*"}
$updatelist2016 = Get-WSUSUpdate -Approval Approved -Status Any | Where-Object {$_.Update.title -like "*sql*" -and $_.Update.title -like "*2016*"}

#For loop to collect the 2012 SQL patches.
For ($i=0; $i -lt 50; $i++){
   $d = $updatelist2012[$i].update.KnowledgebaseArticles
   $fileuri5 = Get-PSWSUSUpdateFile -UpdateName $d | Select-Object FileUri
   For ($t=0; $t -lt 50; $t++){
      $a = $fileuri5[$t]
      $a = $a -Replace "http://<wsus>:<port>/Content", "<wsus_patches_location>"
      $a = $a -Replace "}", ""
      $a = $a -Replace "@{FileUri=", ""
      copy-item $a E:\wsusoffline\<place_to_put_patch_locally>
   }
}

#For loop to collect the 2014 SQL patches.
For ($i=0; $i -lt 50; $i++){
   $d = $updatelist2014[$i].update.KnowledgebaseArticles
   $fileuri5 = Get-PSWSUSUpdateFile -UpdateName $d | Select-Object FileUri
   For ($t=0; $t -lt 50; $t++){
      $a = $fileuri5[$t]
      $a = $a -Replace "http://<wsus>:<port>/Content", "<wsus_patches_location>"
      $a = $a -Replace "}", ""
      $a = $a -Replace "@{FileUri=", ""
      copy-item $a E:\wsusoffline\<place_to_put_patch_locally>
   }
}

#For loop to collect the 2016 SQL patches.
For ($i=0; $i -lt 50; $i++){
   $d = $updatelist2016[$i].update.KnowledgebaseArticles
   $fileuri5 = Get-PSWSUSUpdateFile -UpdateName $d | Select-Object FileUri
   For ($t=0; $t -lt 50; $t++){
      $a = $fileuri5[$t]
      $a = $a -Replace "http://<wsus>:<port>/Content", "<wsus_patches_location>"
      $a = $a -Replace "}", ""
      $a = $a -Replace "@{FileUri=", ""
      copy-item $a E:\wsusoffline\<place_to_put_patch_locally>
   }
}

#Completed
exit
anienigma
 
Posts: 5
Joined: 07.09.2017, 15:55

Return to Anregungen / Suggestions

Who is online

Users browsing this forum: Google [Bot] and 7 guests

cron