Function Invoke-WUInstall
        Invoke Get-WUInstall remotely.
        Use Invoke-WUInstall to invoke Windows Update install remotly. It Based on TaskScheduler because
        CreateUpdateDownloader() and CreateUpdateInstaller() methods can't be called from a remote computer - E_ACCESSDENIED.
        Because we do not have the ability to interact, is recommended use -AcceptAll with WUInstall filters in script block.
    .PARAMETER ComputerName
        Specify computer name.
    .PARAMETER TaskName
        Specify task name. Default is PSWindowsUpdate.
    .PARAMETER Script
        Specify PowerShell script block that you what to run. Default is {ipmo PSWindowsUpdate; Get-WUInstall -AcceptAll | Out-File C:\PSWindowsUpdate.log}
        PS C:\> $Script = {ipmo PSWindowsUpdate; Get-WUInstall -AcceptAll -AutoReboot | Out-File C:\PSWindowsUpdate.log}
        PS C:\> Invoke-WUInstall -ComputerName -Script $Script
        PS C:\> Get-Content \\\c$\PSWindowsUpdate.log
        Author: Michal Gajda
        Blog :

        [String]$TaskName = "PSWindowsUpdate",
        [ScriptBlock]$Script = {ipmo PSWindowsUpdate; Get-WUInstall -AcceptAll | Out-File C:\PSWindowsUpdate.log},

        $User = [Security.Principal.WindowsIdentity]::GetCurrent()
        $Role = (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)

            Write-Warning "To perform some operations you must run an elevated Windows PowerShell console."    
        } #End If !$Role
        $PSWUModule = Get-Module -Name PSWindowsUpdate -ListAvailable
        Write-Verbose "Create schedule service object"
        $Scheduler = New-Object -ComObject Schedule.Service
        $Task = $Scheduler.NewTask(0)

        $RegistrationInfo = $Task.RegistrationInfo
        $RegistrationInfo.Description = $TaskName
        $RegistrationInfo.Author = $User.Name

        $Settings = $Task.Settings
        $Settings.Enabled = $True
        $Settings.StartWhenAvailable = $True
        $Settings.Hidden = $False

        $Action = $Task.Actions.Create(0)
        $Action.Path = "powershell"
        $Action.Arguments = "-Command $Script"
        $Task.Principal.RunLevel = 1    
        ForEach($Computer in $ComputerName)
            If ($pscmdlet.ShouldProcess($Computer,"Invoke WUInstall")) 
                if(Test-Connection -ComputerName $Computer -Quiet)
                    Write-Verbose "Check PSWindowsUpdate module on $Computer"
                        $ModuleTest = Invoke-Command -ComputerName $Computer -ScriptBlock {Get-Module -ListAvailable -Name PSWindowsUpdate} -ErrorAction Stop
                    } #End Try
                        Write-Warning "Can't access to machine $Computer. Try use: winrm qc"
                    } #End Catch
                    $ModulStatus = $false
                    if($ModuleTest -eq $null -or $ModuleTest.Version -lt $PSWUModule.Version)
                            Update-WUModule -ComputerName $Computer
                        } #End If $OnlineUpdate
                            Update-WUModule -ComputerName $Computer    -LocalPSWUSource (Get-Module -ListAvailable -Name PSWindowsUpdate).ModuleBase
                        } #End Else $OnlineUpdate
                    } #End If $ModuleTest -eq $null -or $ModuleTest.Version -lt $PSWUModule.Version
                    #Sometimes can't connect at first time
                    $Info = "Connect to scheduler and register task on $Computer"
                    for ($i=1; $i -le 3; $i++)
                        $Info += "."
                        Write-Verbose $Info
                        } #End Try
                            if($i -ge 3)
                                Write-Error "Can't connect to Schedule service on $Computer" -ErrorAction Stop
                            } #End If $i -ge 3
                                sleep -Seconds 1
                            } #End Else $i -ge 3
                        } #End Catch
                    } #End For $i=1; $i -le 3; $i++
                    $RootFolder = $Scheduler.GetFolder("\")
                    $SendFlag = 1
                    if($Scheduler.GetRunningTasks(0) | Where-Object {$_.Name -eq $TaskName})
                        $CurrentTask = $RootFolder.GetTask($TaskName)
                        $Title = "Task $TaskName is curretly running: $($CurrentTask.Definition.Actions | Select-Object -exp Path) $($CurrentTask.Definition.Actions | Select-Object -exp Arguments)"
                        $Message = "What do you want to do?"

                        $ChoiceContiniue = New-Object System.Management.Automation.Host.ChoiceDescription "&Continue Current Task"
                        $ChoiceStart = New-Object System.Management.Automation.Host.ChoiceDescription "Stop and Start &New Task"
                        $ChoiceStop = New-Object System.Management.Automation.Host.ChoiceDescription "&Stop Task"
                        $Options = [System.Management.Automation.Host.ChoiceDescription[]]($ChoiceContiniue, $ChoiceStart, $ChoiceStop)
                        $SendFlag = $host.ui.PromptForChoice($Title, $Message, $Options, 0)
                        if($SendFlag -ge 1)
                        } #End If $SendFlag -eq 1
                    } #End If !($Scheduler.GetRunningTasks(0) | Where-Object {$_.Name -eq $TaskName})
                    if($SendFlag -eq 1)
                        $RootFolder.RegisterTaskDefinition($TaskName, $Task, 6, "SYSTEM", $Null, 1) | Out-Null
                        $RootFolder.GetTask($TaskName).Run(0) | Out-Null
                    } #End If $SendFlag -eq 1
                } #End If Test-Connection -ComputerName $Computer -Quiet
                    Write-Warning "Machine $Computer is not responding."
                } #End Else Test-Connection -ComputerName $Computer -Quiet
            } #End If $pscmdlet.ShouldProcess($Computer,"Invoke WUInstall")
        } #End ForEach $Computer in $ComputerName
        Write-Verbose "Invoke-WUInstall complete."
    End {}