Common/ServerRake.Common.Update.ps1

##################################
### COMMON FUNCTIONS: UPDATE ###
##################################

function Install-OSSecurityPatches {

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string[]] $ComputerName,

        [Parameter(Mandatory = $true)]
        [string] $Folder
    )

    $remoteScript = {
            
        param ($Folder)

        $path = "C:\TEMP\Patching\$Folder\"
        $patches = Get-ChildItem -Path $path

        foreach ($patch in $patches.Name) {

            expand -f:*.cab "$($path)$($patch)" "$($path)"

            $kb = $patch.Split('-')[1]
            $cab = $patches | ? { $_.Name -match $kb -and $_.Name -like "*.cab" }

            dism.exe /online /add-package /packagepath:"$($path)$($cab)" /quiet /norestart /LogPath:"$($path)$($ENV:COMPUTERNAME)_$($kb).log" /LogLevel:4

            Write-Host "[$ENV:COMPUTERNAME] [$kb] Install Complete!`n" -ForegroundColor Green

        }

        Remove-Item -Path "$($path)*.cab"

    }

    Send-RemoteScript -ComputerName $ComputerName -RemoteScript $remoteScript -ArgumentList $Folder

}