Skip to content

Instantly share code, notes, and snippets.

@altrive
Last active November 12, 2019 16:23
Show Gist options
  • Select an option

  • Save altrive/5268181 to your computer and use it in GitHub Desktop.

Select an option

Save altrive/5268181 to your computer and use it in GitHub Desktop.

Revisions

  1. altrive revised this gist Apr 13, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,6 @@ $params=@{
    #Remove files that updated periodically
    Get-ChildItem $params.DownloadFolder | where Name -Like "am_delta_*.exe" | Remove-Item #Windows Defender Definition
    Get-ChildItem $params.DownloadFolder | where Name -Like "im*.cab" | Remove-Item #IME patch
    Get-ChildItem $params.DownloadFolder | where Name -Like "windows-kb890830-*.cab" | Remove-Item #Windows Malicious Software Removal Tool
    Get-ChildItem $params.DownloadFolder | where Name -Like "windows-kb890830-*.exe" | Remove-Item #Windows Malicious Software Removal Tool
    Start-DownloadWindowsUpdateFile @params -Verbose
    ```
  2. altrive revised this gist Apr 13, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,8 @@ param(

    #Append to download list
    $url = $content.DownloadURL
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url;IsInstalled=$isInstalled;RebootRequired=$rebootRequired}
    $fileName = [IO.Path]::GetFileName($url)
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url;IsInstalled=$isInstalled;RebootRequired=$rebootRequired;FileName=$fileName}
    }
    }
    }
    @@ -67,6 +68,8 @@ param(

    Write-Verbose ("WindowsUpdate check completed: {0} files found" -f $results.Count)

    #$results | select Title,FileName, LastDeploymentChangeTime | Format-List

    #Start Download Files
    Write-Verbose ("Download files started...")
    foreach($update in $results)
  3. altrive revised this gist Apr 13, 2013. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,9 @@ $params=@{
    WindowsUpdateFilte = "IsHidden=0"
    }
    #Remove WindowsDefender Definition File(Updated Daily)
    Get-ChildItem $params.DownloadFolder | where Name -Like "am_delta_*.exe" | Remove-Item
    #Remove files that updated periodically
    Get-ChildItem $params.DownloadFolder | where Name -Like "am_delta_*.exe" | Remove-Item #Windows Defender Definition
    Get-ChildItem $params.DownloadFolder | where Name -Like "im*.cab" | Remove-Item #IME patch
    Get-ChildItem $params.DownloadFolder | where Name -Like "windows-kb890830-*.cab" | Remove-Item #Windows Malicious Software Removal Tool
    Start-DownloadWindowsUpdateFile @params -Verbose
    ```
  4. altrive revised this gist Apr 13, 2013. 2 changed files with 5 additions and 10 deletions.
    12 changes: 3 additions & 9 deletions Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,6 @@ param(
    [Parameter(Mandatory=$True)]
    [string] $Filter
    )
    <#
    #Need CreateInstance to kick WindowsUpdate from Remote Computer?
    $objSession = [Activator]::CreateInstance([Type]::GetTypeFromProgID("Microsoft.Update.Session",$env:ComputerName))
    #>
    $objSession = New-Object -ComObject "Microsoft.Update.Session"
    $objSearcher = $objSession.CreateUpdateSearcher()
    $results = $objSearcher.Search($Filter)
    @@ -48,10 +44,11 @@ function Start-DownloadWindowsUpdateFile
    [Cmdletbinding()]
    param(
    [string] $TargetComputer,
    $Credential,
    [string] $DownloadFolder,
    [string] $WindowsUpdateFilter
    )
    if(!(Test-Path $destination))
    if(!(Test-Path $DownloadFolder))
    {
    Write-Error "Destination folder not found!"
    }
    @@ -64,11 +61,8 @@ param(
    }
    else
    {
    if($cred -eq $null){
    $cred = Get-Credential -UserName "localhost\Administrator" -Message "Enter credential"
    }
    Write-Verbose ("Search WindowsUpdate for remote computer({0})..." -f $TargetComputer)
    $results = Invoke-Command -Computer $TargetComputer -Credential $cred -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $WindowsUpdateFilter
    $results = Invoke-Command -Computer $TargetComputer -Credential $Credential -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $WindowsUpdateFilter
    }

    Write-Verbose ("WindowsUpdate check completed: {0} files found" -f $results.Count)
    3 changes: 2 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,8 @@ and download files to network share.

    ``` powershell
    $params=@{
    TargetComputer = "172.16.100.57"
    TargetComputer = "172.16.100.2"
    Credential = Get-Credential -UserName "localhost\Administrator" -Message "Enter credential"
    DownloadFolder = "\\172.16.0.1\Shared\Images\WindowsUpdate\Windows8"
    WindowsUpdateFilte = "IsHidden=0"
    }
  5. altrive revised this gist Apr 4, 2013. 2 changed files with 7 additions and 3 deletions.
    5 changes: 3 additions & 2 deletions Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -56,6 +56,7 @@ param(
    Write-Error "Destination folder not found!"
    }


    if($TargetComputer -eq $env:ComputerName)
    {
    Write-Verbose ("Search WindowsUpdate for local computer...")
    @@ -80,11 +81,11 @@ param(
    $filePath = Join-Path $DownloadFolder $fileName
    if(Test-Path $filePath)
    {
    Write-Verbose "Skip already exists patch: $fileName"
    Write-Verbose "`tSkip already exists patch: $fileName"
    continue
    }

    Write-Verbose "Start download patch: $fileName"
    Write-Verbose "`tStart download patch: $fileName"
    $params = @{
    Source = $update.DownloadURL
    DisplayName = $update.Title
    5 changes: 4 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,12 @@ and download files to network share.

    ``` powershell
    $params=@{
    TargetComputer = "172.16.100.53"
    TargetComputer = "172.16.100.57"
    DownloadFolder = "\\172.16.0.1\Shared\Images\WindowsUpdate\Windows8"
    WindowsUpdateFilte = "IsHidden=0"
    }
    #Remove WindowsDefender Definition File(Updated Daily)
    Get-ChildItem $params.DownloadFolder | where Name -Like "am_delta_*.exe" | Remove-Item
    Start-DownloadWindowsUpdateFile @params -Verbose
    ```
  6. altrive revised this gist Apr 3, 2013. 2 changed files with 60 additions and 32 deletions.
    57 changes: 55 additions & 2 deletions Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #Requires Version 3

    #Get WindowsUpdate List for offline patch
    function Get-WindowsUpdateFileList
    {
    @@ -12,8 +14,6 @@ param(
    $objSession = New-Object -ComObject "Microsoft.Update.Session"
    $objSearcher = $objSession.CreateUpdateSearcher()
    $results = $objSearcher.Search($Filter)

    #Write-Debug $results.Updates.Count

    $downloadList =@()
    foreach($update in $results.Updates)
    @@ -41,4 +41,57 @@ param(
    }
    }
    return $downloadList
    }

    function Start-DownloadWindowsUpdateFile
    {
    [Cmdletbinding()]
    param(
    [string] $TargetComputer,
    [string] $DownloadFolder,
    [string] $WindowsUpdateFilter
    )
    if(!(Test-Path $destination))
    {
    Write-Error "Destination folder not found!"
    }

    if($TargetComputer -eq $env:ComputerName)
    {
    Write-Verbose ("Search WindowsUpdate for local computer...")
    $results = Get-WindowsUpdateFileList $WindowsUpdateFilter
    }
    else
    {
    if($cred -eq $null){
    $cred = Get-Credential -UserName "localhost\Administrator" -Message "Enter credential"
    }
    Write-Verbose ("Search WindowsUpdate for remote computer({0})..." -f $TargetComputer)
    $results = Invoke-Command -Computer $TargetComputer -Credential $cred -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $WindowsUpdateFilter
    }

    Write-Verbose ("WindowsUpdate check completed: {0} files found" -f $results.Count)

    #Start Download Files
    Write-Verbose ("Download files started...")
    foreach($update in $results)
    {
    $fileName = [IO.Path]::GetFileName($update.DownloadURL)
    $filePath = Join-Path $DownloadFolder $fileName
    if(Test-Path $filePath)
    {
    Write-Verbose "Skip already exists patch: $fileName"
    continue
    }

    Write-Verbose "Start download patch: $fileName"
    $params = @{
    Source = $update.DownloadURL
    DisplayName = $update.Title
    Description = $update.DownloadURL
    Destination = $DownloadFolder
    }
    Start-BitsTransfer @params
    }
    Write-Verbose ("Download files completed...")
    }
    35 changes: 5 additions & 30 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -11,35 +11,10 @@ following sample check WindowsUpdate for specified computer,
    and download files to network share.

    ``` powershell
    #Requires –Version 3
    #Requires –Modules PShould
    $target = $env:COMPUTERNAME
    #$filter = "IsAssigned=1 and IsHidden=0"
    $filter = "IsHidden=0"
    if($cred -eq $null){
    $cred = Get-Credential -UserName "localhost\Administrator" -Message "Enter credential"
    }
    #Get WindowsUpdate file list for target computer(if not domain environment -Credential parameter needed)
    $results = Invoke-Command -Computer $target -Credential $cred -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $filter
    #Download files
    $destination= "\\172.16.0.1\Shared\Images\WindowsUpdate\WindowsServer2012"
    if(!(Test-Path $destination)){
    Write-Error "Destination folder not found!"
    }
    foreach($update in $results)
    {
    $params = @{
    Source = $update.DownloadURL
    DisplayName = $update.Title
    Description = $update.DownloadURL
    Destination = $destination
    }
    Start-BitsTransfer @params
    $params=@{
    TargetComputer = "172.16.100.53"
    DownloadFolder = "\\172.16.0.1\Shared\Images\WindowsUpdate\Windows8"
    WindowsUpdateFilte = "IsHidden=0"
    }
    Start-DownloadWindowsUpdateFile @params -Verbose
    ```
  7. altrive revised this gist Apr 2, 2013. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -11,15 +11,27 @@ following sample check WindowsUpdate for specified computer,
    and download files to network share.

    ``` powershell
    #Requires –Version 3
    #Requires –Modules PShould
    $target = $env:COMPUTERNAME
    #$filter = "IsAssigned=1 and IsHidden=0"
    $filter = "IsHidden=0"
    if($cred -eq $null){
    $cred = Get-Credential -UserName "localhost\Administrator" -Message "Enter credential"
    }
    #Get WindowsUpdate file list for target computer(if not domain environment -Credential parameter needed)
    $results = Invoke-Command -Computer $target -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $filter
    $results = Invoke-Command -Computer $target -Credential $cred -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $filter
    #Download files
    $destination= "\\172.16.0.1\Shared\Images\WindowsUpdate\WindowsServer2012"
    if(!(Test-Path $destination)){
    Write-Error "Destination folder not found!"
    }
    foreach($update in $results)
    {
    $params = @{
  8. altrive revised this gist Apr 1, 2013. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -27,14 +27,15 @@ param(
    {
    foreach($content in $bundledUpdate.DownloadContents)
    {
    $url = $content.DownloadURL
    if($url.Contains("-express_") -or $url.Contains("-delta_") -or $url.EndsWith(".psf"))
    #if($url.Contains("-express_") -or $url.Contains("-delta_") -or $url.EndsWith(".psf"))
    if($content.IsDeltaCompressedContent)
    {
    #Skip express package(Delta Compressed Package) and .psf file
    continue
    }

    #Append to download list
    $url = $content.DownloadURL
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url;IsInstalled=$isInstalled;RebootRequired=$rebootRequired}
    }
    }
  9. altrive revised this gist Mar 29, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,7 @@ param(
    $title = $update.Title
    $date = $update.LastDeploymentChangeTime
    $isInstalled = $update.IsInstalled
    $rebootRequired = $update.RebootRequired

    foreach($bundledUpdate in $update.BundledUpdates)
    {
    @@ -34,7 +35,7 @@ param(
    }

    #Append to download list
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url;IsInstalled=$isInstalled}
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url;IsInstalled=$isInstalled;RebootRequired=$rebootRequired}
    }
    }
    }
  10. altrive revised this gist Mar 29, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ param(
    foreach($content in $bundledUpdate.DownloadContents)
    {
    $url = $content.DownloadURL
    if($url.Contains("-express_") -or $url.EndsWith(".psf"))
    if($url.Contains("-express_") -or $url.Contains("-delta_") -or $url.EndsWith(".psf"))
    {
    #Skip express package(Delta Compressed Package) and .psf file
    continue
  11. altrive revised this gist Mar 29, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,8 @@ and download files to network share.

    ``` powershell
    $target = $env:COMPUTERNAME
    $filter = "IsAssigned=1 and IsHidden=0"
    #$filter = "IsAssigned=1 and IsHidden=0"
    $filter = "IsHidden=0"
    #Get WindowsUpdate file list for target computer(if not domain environment -Credential parameter needed)
    $results = Invoke-Command -Computer $target -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $filter
  12. altrive revised this gist Mar 29, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ and download files to network share.
    $target = $env:COMPUTERNAME
    $filter = "IsAssigned=1 and IsHidden=0"
    #Get WindowsUpdate file list for target computer
    #Get WindowsUpdate file list for target computer(if not domain environment -Credential parameter needed)
    $results = Invoke-Command -Computer $target -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $filter
    #Download files
  13. altrive revised this gist Mar 29, 2013. 2 changed files with 4 additions and 3 deletions.
    5 changes: 3 additions & 2 deletions Get-WindowsUpdateList.ps1 → Get-WindowsUpdateFileList.ps1
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #Get WindowsUpdate List for offline patch
    function Get-WindowsUpdateList
    function Get-WindowsUpdateFileList
    {
    param(
    [Parameter(Mandatory=$True)]
    @@ -20,6 +20,7 @@ param(
    {
    $title = $update.Title
    $date = $update.LastDeploymentChangeTime
    $isInstalled = $update.IsInstalled

    foreach($bundledUpdate in $update.BundledUpdates)
    {
    @@ -33,7 +34,7 @@ param(
    }

    #Append to download list
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url}
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url;IsInstalled=$isInstalled}
    }
    }
    }
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ $target = $env:COMPUTERNAME
    $filter = "IsAssigned=1 and IsHidden=0"
    #Get WindowsUpdate file list for target computer
    $results = Invoke-Command -Computer $target -ScriptBlock ${function:Get-WindowsUpdateFile} -ArgumentList $filter
    $results = Invoke-Command -Computer $target -ScriptBlock ${function:Get-WindowsUpdateFileList} -ArgumentList $filter
    #Download files
    $destination= "\\172.16.0.1\Shared\Images\WindowsUpdate\WindowsServer2012"
  14. altrive created this gist Mar 29, 2013.
    41 changes: 41 additions & 0 deletions Get-WindowsUpdateList.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #Get WindowsUpdate List for offline patch
    function Get-WindowsUpdateList
    {
    param(
    [Parameter(Mandatory=$True)]
    [string] $Filter
    )
    <#
    #Need CreateInstance to kick WindowsUpdate from Remote Computer?
    $objSession = [Activator]::CreateInstance([Type]::GetTypeFromProgID("Microsoft.Update.Session",$env:ComputerName))
    #>
    $objSession = New-Object -ComObject "Microsoft.Update.Session"
    $objSearcher = $objSession.CreateUpdateSearcher()
    $results = $objSearcher.Search($Filter)

    #Write-Debug $results.Updates.Count

    $downloadList =@()
    foreach($update in $results.Updates)
    {
    $title = $update.Title
    $date = $update.LastDeploymentChangeTime

    foreach($bundledUpdate in $update.BundledUpdates)
    {
    foreach($content in $bundledUpdate.DownloadContents)
    {
    $url = $content.DownloadURL
    if($url.Contains("-express_") -or $url.EndsWith(".psf"))
    {
    #Skip express package(Delta Compressed Package) and .psf file
    continue
    }

    #Append to download list
    $downloadList += [pscustomobject]@{Title=$title;LastDeploymentChangeTime=$date ;DownloadURL=$url}
    }
    }
    }
    return $downloadList
    }
    32 changes: 32 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    Summary
    ----
    PowerShell cmdlets to check WindowsUpdate and return patch list.

    This script is intended for offline Windows patching.
    (MBSA 2.2 currently not support Windows 8/Windows Server 2012)

    Usage
    ---
    following sample check WindowsUpdate for specified computer,
    and download files to network share.

    ``` powershell
    $target = $env:COMPUTERNAME
    $filter = "IsAssigned=1 and IsHidden=0"
    #Get WindowsUpdate file list for target computer
    $results = Invoke-Command -Computer $target -ScriptBlock ${function:Get-WindowsUpdateFile} -ArgumentList $filter
    #Download files
    $destination= "\\172.16.0.1\Shared\Images\WindowsUpdate\WindowsServer2012"
    foreach($update in $results)
    {
    $params = @{
    Source = $update.DownloadURL
    DisplayName = $update.Title
    Description = $update.DownloadURL
    Destination = $destination
    }
    Start-BitsTransfer @params
    }
    ```