Public/Invoke-TunerPatching.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#requires -RunAsAdministrator
function Invoke-TunerPatching {
    <#
    .SYNOPSIS
        Installs pending updates for Windows computer
    .DESCRIPTION
        Installs pending updates for Windows computer
    .EXAMPLE
        Invoke-TunerPatching
    .LINK
        https://www.powershellgallery.com/packages/PSWindowsUpdate
        https://chocolatey.org
    #>

    [CmdletBinding(SupportsShouldProcess=$True)]
    param()
    try {
        Write-Host "installing pending updates..." -ForegroundColor Cyan
        $ulist = Get-WindowsUpdate
        if ($ulist.Count -gt 0) {
            Get-WindowsUpdate -Download -AcceptAll -RecurseCycle 3 -Install -IgnoreReboot -Confirm:$False -ErrorAction Stop
        }
        else {
            Write-Host "no pending updates were found" -ForegroundColor Green
        }
    }
    catch {
        Write-Error $Error[0].Exception.Message
    }
}

Export-ModuleMember -Function Invoke-TunerPatching