This shows you the differences between two versions of the page.
userspace:windows_updates_-_powershell [2017/03/02 09:45] trabs-ol |
userspace:windows_updates_-_powershell [2021/08/23 08:37] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | Mit diesem Script werden so lange Updates intstalliert bis keine mehr vorliegen. Die Updates werden nur nach 19 Uhr und vor 7 Uhr installiert um den User nicht an der Anmeldung zu hindern. Aussnahme: Der Rechner wurde neu installiert, | ||
- | Voraussetzungen: | ||
- | |||
- | setup64.ins | ||
- | |||
- | <code winst> | ||
- | ; Copyright (c) uib gmbh (www.uib.de) | ||
- | ; This sourcecode is owned by uib | ||
- | ; and published under the Terms of the General Public License. | ||
- | ; credits: http:// | ||
- | ; comment | ||
- | |||
- | [Actions] | ||
- | requiredWinstVersion >= " | ||
- | AutoActivityDisplay = true | ||
- | StayOnTop = false | ||
- | |||
- | DefVar $LogDir$ | ||
- | DefVar $ProductId$ | ||
- | DefVar $MinimumSpace$ | ||
- | DefVar $ExitCode$ | ||
- | |||
- | Set $LogDir$ = " | ||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | ; - Please edit the following values | ||
- | ; ---------------------------------------------------------------- | ||
- | ; | ||
- | ; therefore please: only lower letters, no umlauts, | ||
- | ; no white space use ' | ||
- | Set $ProductId$ | ||
- | Set $MinimumSpace$ | ||
- | ; ---------------------------------------------------------------- | ||
- | |||
- | if not(HasMinimumSpace (" | ||
- | LogError "Not enough space on %SystemDrive%, | ||
- | isFatalError | ||
- | ; Stop process and set installation status to failed | ||
- | else | ||
- | comment "Show product picture" | ||
- | ShowBitmap " | ||
- | |||
- | Files_Install /Sysnative | ||
- | Message " | ||
- | DosInAnIcon_WindowsUpate | ||
- | Sub_check_exitcode | ||
- | |||
- | endif | ||
- | |||
- | [Files_Install] | ||
- | CheckTargetPath = " | ||
- | copy -u " | ||
- | |||
- | [DosInAnIcon_WindowsUpate] | ||
- | " | ||
- | |||
- | [Sub_check_exitcode] | ||
- | comment "Test for installation success via exit code" | ||
- | set $ExitCode$ = getLastExitCode | ||
- | ; informations to exit codes see | ||
- | ; http:// | ||
- | ; http:// | ||
- | if ($ExitCode$ = " | ||
- | comment "Looks good: setup program gives exitcode zero" | ||
- | else | ||
- | comment "Setup program gives a exitcode unequal zero: " + $ExitCode$ | ||
- | if ($ExitCode$ = " | ||
- | comment " | ||
- | comment " | ||
- | else | ||
- | if ($ExitCode$ = " | ||
- | comment "looks good: setup program gives exitcode 1641" | ||
- | comment " | ||
- | else | ||
- | if ($ExitCode$ = " | ||
- | comment "looks good: setup program gives exitcode 3010" | ||
- | comment " | ||
- | ExitWindows / | ||
- | else | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | endif | ||
- | endif | ||
- | endif | ||
- | </ | ||
- | |||
- | once64.ins | ||
- | <code winst> | ||
- | ; Copyright (c) uib gmbh (www.uib.de) | ||
- | ; This sourcecode is owned by uib | ||
- | ; and published under the Terms of the General Public License. | ||
- | ; credits: http:// | ||
- | ; comment | ||
- | |||
- | [Actions] | ||
- | requiredWinstVersion >= " | ||
- | AutoActivityDisplay = true | ||
- | StayOnTop = false | ||
- | |||
- | DefVar $LogDir$ | ||
- | DefVar $ProductId$ | ||
- | DefVar $MinimumSpace$ | ||
- | DefVar $ExitCode$ | ||
- | |||
- | Set $LogDir$ = " | ||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | ; - Please edit the following values | ||
- | ; ---------------------------------------------------------------- | ||
- | ; | ||
- | ; therefore please: only lower letters, no umlauts, | ||
- | ; no white space use ' | ||
- | Set $ProductId$ | ||
- | Set $MinimumSpace$ | ||
- | ; ---------------------------------------------------------------- | ||
- | |||
- | if not(HasMinimumSpace (" | ||
- | LogError "Not enough space on %SystemDrive%, | ||
- | isFatalError | ||
- | ; Stop process and set installation status to failed | ||
- | else | ||
- | comment "Show product picture" | ||
- | ShowBitmap " | ||
- | |||
- | Files_Install /Sysnative | ||
- | Message " | ||
- | DosInAnIcon_WindowsUpate | ||
- | Sub_check_exitcode | ||
- | |||
- | endif | ||
- | |||
- | [Files_Install] | ||
- | CheckTargetPath = " | ||
- | copy -u " | ||
- | |||
- | [DosInAnIcon_WindowsUpate] | ||
- | " | ||
- | |||
- | [Sub_check_exitcode] | ||
- | comment "Test for installation success via exit code" | ||
- | set $ExitCode$ = getLastExitCode | ||
- | ; informations to exit codes see | ||
- | ; http:// | ||
- | ; http:// | ||
- | if ($ExitCode$ = " | ||
- | comment "Looks good: setup program gives exitcode zero" | ||
- | else | ||
- | comment "Setup program gives a exitcode unequal zero: " + $ExitCode$ | ||
- | if ($ExitCode$ = " | ||
- | comment " | ||
- | comment " | ||
- | else | ||
- | if ($ExitCode$ = " | ||
- | comment "looks good: setup program gives exitcode 1641" | ||
- | comment " | ||
- | else | ||
- | if ($ExitCode$ = " | ||
- | comment "looks good: setup program gives exitcode 3010" | ||
- | comment " | ||
- | ExitWindows / | ||
- | else | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | endif | ||
- | endif | ||
- | endif | ||
- | </ | ||
- | |||
- | control | ||
- | |||
- | < | ||
- | [Package] | ||
- | version: 19 | ||
- | depends: | ||
- | incremental: | ||
- | |||
- | [Product] | ||
- | type: localboot | ||
- | id: install-windows-updates | ||
- | name: Updates für Windows installieren | ||
- | description: | ||
- | advice: | ||
- | version: 4.0 | ||
- | priority: -80 | ||
- | licenseRequired: | ||
- | productClasses: | ||
- | setupScript: | ||
- | uninstallScript: | ||
- | updateScript: | ||
- | alwaysScript: | ||
- | onceScript: once64.ins | ||
- | customScript: | ||
- | userLoginScript: | ||
- | </ | ||
- | |||
- | install-updates.ps1 | ||
- | |||
- | < | ||
- | function Write-Log | ||
- | { | ||
- | [CmdletBinding()] | ||
- | param( | ||
- | [Parameter(Mandatory=$True, | ||
- | [Array[]]$logstring | ||
- | ) | ||
- | foreach ($string in $logstring) { | ||
- | $nowDate = Get-Date -Format dd.MM.yyyy | ||
- | $nowTime = Get-Date -Format HH:mm:ss | ||
- | Write-Host $nowDate $nowTime $string | ||
- | Add-Content -LiteralPath $LogPath -Value " | ||
- | } | ||
- | } | ||
- | |||
- | function Get-Timewindow | ||
- | { | ||
- | $Now = Get-Date | ||
- | if (($Now.Hour -ge 7) -and ($Now.Hour -le 19)) | ||
- | { | ||
- | Write-Log 'It is daytime. Check if System was just getting installed.' | ||
- | $InstallDate = ([WMI]'' | ||
- | $OneDay = New-TimeSpan -Days 1 | ||
- | |||
- | if ((($Now) -$InstallDate) -lt $OneDay) | ||
- | { | ||
- | Write-Log 'OS installation time is not older than 1 day. Windows Updates must be installed. Continue...' | ||
- | } | ||
- | else | ||
- | { | ||
- | Write-Log 'OS installation time is older than 1 day. Doing nothing because its day.' | ||
- | Write-Log '***** END *****' | ||
- | exit 0 | ||
- | } | ||
- | } | ||
- | else | ||
- | { | ||
- | Write-Log 'It is night. Continue...' | ||
- | } | ||
- | } | ||
- | |||
- | function Get-Rebootrequired | ||
- | { | ||
- | $objSystemInfo= New-Object -ComObject ' | ||
- | $RebootRequired = $objSystemInfo.RebootRequired | ||
- | if ($RebootRequired -eq $true) | ||
- | { | ||
- | Write-Log 'Need to reboot, rebooting...' | ||
- | exit 3010 | ||
- | } | ||
- | else | ||
- | { | ||
- | Write-Log 'No need to reboot.' | ||
- | } | ||
- | } | ||
- | |||
- | function Get-InstallerStatus { | ||
- | $Busy = $true | ||
- | $lastWriteTimeCBSLos = (Get-Item C: | ||
- | $TimespanOneMinute = New-TimeSpan -Minutes 1 | ||
- | while ($Busy -eq $true) | ||
- | { | ||
- | if (((Get-Date) -$lastWriteTimeCBSLos) -gt $TimespanOneMinute) { | ||
- | $Busy = $false | ||
- | } | ||
- | else { | ||
- | Write-Log ' | ||
- | Start-Sleep -Seconds 10 | ||
- | } | ||
- | } | ||
- | | ||
- | } | ||
- | |||
- | |||
- | $LogPath = ' | ||
- | $FirstRun = Test-Path -Path $LogPath | ||
- | |||
- | Write-Log '***** START *****' | ||
- | |||
- | Get-Timewindow | ||
- | Get-Rebootrequired | ||
- | Get-InstallerStatus | ||
- | |||
- | Write-Log ' | ||
- | |||
- | #GUI bauen | ||
- | [System.Windows.Forms.Application]:: | ||
- | Add-Type -AssemblyName System.Windows.Forms | ||
- | $Form = New-Object system.Windows.Forms.Form | ||
- | $Form.Text = ' | ||
- | $Form.Width = 430 | ||
- | $Form.Height = 100 | ||
- | $Form.TopMost = $True | ||
- | $Form.AutoSizeMode = ' | ||
- | $Form.MinimizeBox = $False | ||
- | $Form.MaximizeBox = $False | ||
- | $Form.WindowState = ' | ||
- | $Form.SizeGripStyle = ' | ||
- | $Form.ShowInTaskbar = $False | ||
- | $Form.StartPosition = ' | ||
- | $Font = New-Object System.Drawing.Font(' | ||
- | $Form.Font = $Font | ||
- | $Label = New-Object System.Windows.Forms.Label | ||
- | $Label.Text = 'Suche nach Windows Updates...' | ||
- | $Label.AutoSize = $True | ||
- | $Form.Controls.Add($Label) | ||
- | $Form.Show() | ||
- | $Form.Focus() | ||
- | |||
- | $Session= New-Object -ComObject Microsoft.Update.Session | ||
- | $Searcher= $Session.CreateUpdateSearcher() | ||
- | |||
- | $SearchResults = $Searcher.Search(" | ||
- | if ($SearchResults.Count -eq 0 -and $FirstRun -eq $true) | ||
- | { | ||
- | Write-Log 'No Updates found.' | ||
- | Write-Log '***** END *****' | ||
- | $Label.Text = 'Keine neuen Updates gefunden.' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $Form.Close() | ||
- | exit 0 | ||
- | } | ||
- | |||
- | if ($SearchResults.Count -eq 0 -and $FirstRun -eq $false) | ||
- | { | ||
- | Write-Log 'No Updates found, but it is the first time to search for updates. Reboot!' | ||
- | Write-Log '***** END *****' | ||
- | $Label.Text = 'Keine Updates gefunden, neuer Versuch...' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $form.Close() | ||
- | exit 3010 | ||
- | } | ||
- | |||
- | foreach ($Update in $SearchResults) { | ||
- | $TotalUpdateSize = $Update.MaxDownloadSize + $TotalUpdateSize | ||
- | Write-Log "Found KB$($update.KBArticleIDs), | ||
- | } | ||
- | |||
- | Write-Log " | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | Write-Log ' | ||
- | $Label.Text = ' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | |||
- | # ProgressBar bauen | ||
- | $ProgressBarSize = New-Object System.Drawing.Size | ||
- | $ProgressBarSize.Width = 400 | ||
- | $ProgressBarSize.Height = 20 | ||
- | $ProgressBar = New-Object System.Windows.Forms.ProgressBar | ||
- | $ProgressBar.Left = 5 | ||
- | $ProgressBar.Top = 35 | ||
- | $ProgressBar.Style = ' | ||
- | $ProgressBar.Value = 0 | ||
- | $ProgressBar.Size = $ProgressBarSize | ||
- | $Form.Controls.Add($ProgressBar) | ||
- | |||
- | $ProgressInPercent = 0 | ||
- | $DownloadCount = 0 | ||
- | $DownloadSuccessCounter = 0 | ||
- | $DownloadFailedCounter = 0 | ||
- | |||
- | foreach ($DownloadItem in $SearchResults) | ||
- | { | ||
- | $DownloadCount++ | ||
- | $Downloader = $Session.CreateUpdateDownloader() | ||
- | $DownloadItems = New-Object -ComObject Microsoft.Update.UpdateColl | ||
- | $DownloadItems.Add($DownloadItem) | ||
- | $Downloader.Updates = $DownloadItems | ||
- | $DownloadResult = $Downloader.Download() | ||
- | if ($DownloadResult.ResultCode -eq 2) { | ||
- | $DownloadSuccessCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($DownloadCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | } | ||
- | else { | ||
- | $DownloadFailedCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($DownloadCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | |||
- | } | ||
- | } | ||
- | Write-Log " | ||
- | |||
- | Write-Log ' | ||
- | $ProgressBar.Value = 0 | ||
- | $Label.Text = ' | ||
- | $Form.Refresh() | ||
- | |||
- | $InstallCount = 0 | ||
- | $InstallSuccessCounter = 0 | ||
- | $InstallFailedCounter = 0 | ||
- | foreach ($InstallItem in $SearchResults) | ||
- | { | ||
- | $InstallCount++ | ||
- | $Installer = $Session.CreateUpdateInstaller() | ||
- | $InstallerItems = New-Object -ComObject Microsoft.Update.UpdateColl | ||
- | $InstallerItems.Add($InstallItem) | ||
- | $Installer.Updates = $InstallerItems | ||
- | $InstallResult = $Installer.Install() | ||
- | if ($InstallResult.ResultCode -eq 2) { | ||
- | $InstallSuccessCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($InstallCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | } | ||
- | else { | ||
- | $InstallFailedCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($InstallCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | } | ||
- | } | ||
- | Write-Log " | ||
- | Write-Log ' | ||
- | Write-Log '***** END *****' | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $Label.Text = ' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $Form.Close() | ||
- | exit 3010 | ||
- | </ | ||
- | |||
- | install-updates-once.ps1 | ||
- | |||
- | < | ||
- | function Write-Log | ||
- | { | ||
- | [CmdletBinding()] | ||
- | param( | ||
- | [Parameter(Mandatory=$True, | ||
- | [Array[]]$logstring | ||
- | ) | ||
- | foreach ($string in $logstring) { | ||
- | $nowDate = Get-Date -Format dd.MM.yyyy | ||
- | $nowTime = Get-Date -Format HH:mm:ss | ||
- | Write-Host $nowDate $nowTime $string | ||
- | Add-Content -LiteralPath $LogPath -Value " | ||
- | } | ||
- | } | ||
- | |||
- | function Get-Timewindow | ||
- | { | ||
- | $Now = Get-Date | ||
- | if (($Now.Hour -ge 7) -and ($Now.Hour -le 19)) | ||
- | { | ||
- | Write-Log 'It is daytime. Check if System was just getting installed.' | ||
- | $InstallDate = ([WMI]'' | ||
- | $OneDay = New-TimeSpan -Days 1 | ||
- | |||
- | if ((($Now) -$InstallDate) -lt $OneDay) | ||
- | { | ||
- | Write-Log 'OS installation time is not older than 1 day. Windows Updates must be installed. Continue...' | ||
- | } | ||
- | else | ||
- | { | ||
- | Write-Log 'OS installation time is older than 1 day. Doing nothing because its day.' | ||
- | Write-Log '***** END *****' | ||
- | exit 0 | ||
- | } | ||
- | } | ||
- | else | ||
- | { | ||
- | Write-Log 'It is night. Continue...' | ||
- | } | ||
- | } | ||
- | |||
- | function Get-Rebootrequired | ||
- | { | ||
- | $objSystemInfo= New-Object -ComObject ' | ||
- | $RebootRequired = $objSystemInfo.RebootRequired | ||
- | if ($RebootRequired -eq $true) | ||
- | { | ||
- | Write-Log 'Need to reboot, rebooting...' | ||
- | exit 3010 | ||
- | } | ||
- | else | ||
- | { | ||
- | Write-Log 'No need to reboot.' | ||
- | } | ||
- | } | ||
- | |||
- | function Get-InstallerStatus { | ||
- | $Busy = $true | ||
- | $lastWriteTimeCBSLos = (Get-Item C: | ||
- | $TimespanOneMinute = New-TimeSpan -Minutes 1 | ||
- | while ($Busy -eq $true) | ||
- | { | ||
- | if (((Get-Date) -$lastWriteTimeCBSLos) -gt $TimespanOneMinute) { | ||
- | $Busy = $false | ||
- | } | ||
- | else { | ||
- | Write-Log ' | ||
- | Start-Sleep -Seconds 10 | ||
- | } | ||
- | } | ||
- | | ||
- | } | ||
- | |||
- | |||
- | $LogPath = ' | ||
- | $FirstRun = Test-Path -Path $LogPath | ||
- | |||
- | Write-Log '***** START *****' | ||
- | |||
- | # Auskommetniert für OPSI-Once-Script | ||
- | # Get-Timewindow | ||
- | Get-Rebootrequired | ||
- | Get-InstallerStatus | ||
- | |||
- | Write-Log ' | ||
- | |||
- | #GUI bauen | ||
- | [System.Windows.Forms.Application]:: | ||
- | Add-Type -AssemblyName System.Windows.Forms | ||
- | $Form = New-Object system.Windows.Forms.Form | ||
- | $Form.Text = ' | ||
- | $Form.Width = 430 | ||
- | $Form.Height = 100 | ||
- | $Form.TopMost = $True | ||
- | $Form.AutoSizeMode = ' | ||
- | $Form.MinimizeBox = $False | ||
- | $Form.MaximizeBox = $False | ||
- | $Form.WindowState = ' | ||
- | $Form.SizeGripStyle = ' | ||
- | $Form.ShowInTaskbar = $False | ||
- | $Form.StartPosition = ' | ||
- | $Font = New-Object System.Drawing.Font(' | ||
- | $Form.Font = $Font | ||
- | $Label = New-Object System.Windows.Forms.Label | ||
- | $Label.Text = 'Suche nach Windows Updates...' | ||
- | $Label.AutoSize = $True | ||
- | $Form.Controls.Add($Label) | ||
- | $Form.Show() | ||
- | $Form.Focus() | ||
- | |||
- | $Session= New-Object -ComObject Microsoft.Update.Session | ||
- | $Searcher= $Session.CreateUpdateSearcher() | ||
- | |||
- | $SearchResults = $Searcher.Search(" | ||
- | if ($SearchResults.Count -eq 0 -and $FirstRun -eq $true) | ||
- | { | ||
- | Write-Log 'No Updates found.' | ||
- | Write-Log '***** END *****' | ||
- | $Label.Text = 'Keine neuen Updates gefunden.' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $Form.Close() | ||
- | exit 0 | ||
- | } | ||
- | |||
- | if ($SearchResults.Count -eq 0 -and $FirstRun -eq $false) | ||
- | { | ||
- | Write-Log 'No Updates found, but it is the first time to search for updates. Reboot!' | ||
- | Write-Log '***** END *****' | ||
- | $Label.Text = 'Keine Updates gefunden, neuer Versuch...' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $form.Close() | ||
- | exit 3010 | ||
- | } | ||
- | |||
- | foreach ($Update in $SearchResults) { | ||
- | $TotalUpdateSize = $Update.MaxDownloadSize + $TotalUpdateSize | ||
- | Write-Log "Found KB$($update.KBArticleIDs), | ||
- | } | ||
- | |||
- | Write-Log " | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | Write-Log ' | ||
- | $Label.Text = ' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | |||
- | # ProgressBar bauen | ||
- | $ProgressBarSize = New-Object System.Drawing.Size | ||
- | $ProgressBarSize.Width = 400 | ||
- | $ProgressBarSize.Height = 20 | ||
- | $ProgressBar = New-Object System.Windows.Forms.ProgressBar | ||
- | $ProgressBar.Left = 5 | ||
- | $ProgressBar.Top = 35 | ||
- | $ProgressBar.Style = ' | ||
- | $ProgressBar.Value = 0 | ||
- | $ProgressBar.Size = $ProgressBarSize | ||
- | $Form.Controls.Add($ProgressBar) | ||
- | |||
- | $ProgressInPercent = 0 | ||
- | $DownloadCount = 0 | ||
- | $DownloadSuccessCounter = 0 | ||
- | $DownloadFailedCounter = 0 | ||
- | |||
- | foreach ($DownloadItem in $SearchResults) | ||
- | { | ||
- | $DownloadCount++ | ||
- | $Downloader = $Session.CreateUpdateDownloader() | ||
- | $DownloadItems = New-Object -ComObject Microsoft.Update.UpdateColl | ||
- | $DownloadItems.Add($DownloadItem) | ||
- | $Downloader.Updates = $DownloadItems | ||
- | $DownloadResult = $Downloader.Download() | ||
- | if ($DownloadResult.ResultCode -eq 2) { | ||
- | $DownloadSuccessCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($DownloadCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | } | ||
- | else { | ||
- | $DownloadFailedCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($DownloadCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | |||
- | } | ||
- | } | ||
- | Write-Log " | ||
- | |||
- | Write-Log ' | ||
- | $ProgressBar.Value = 0 | ||
- | $Label.Text = ' | ||
- | $Form.Refresh() | ||
- | |||
- | $InstallCount = 0 | ||
- | $InstallSuccessCounter = 0 | ||
- | $InstallFailedCounter = 0 | ||
- | foreach ($InstallItem in $SearchResults) | ||
- | { | ||
- | $InstallCount++ | ||
- | $Installer = $Session.CreateUpdateInstaller() | ||
- | $InstallerItems = New-Object -ComObject Microsoft.Update.UpdateColl | ||
- | $InstallerItems.Add($InstallItem) | ||
- | $Installer.Updates = $InstallerItems | ||
- | $InstallResult = $Installer.Install() | ||
- | if ($InstallResult.ResultCode -eq 2) { | ||
- | $InstallSuccessCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($InstallCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | } | ||
- | else { | ||
- | $InstallFailedCounter++ | ||
- | Write-Log " | ||
- | $ProgressInPercent = ($InstallCount / $($SearchResults.Count))*100 | ||
- | $ProgressBar.Value = $ProgressInPercent | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | } | ||
- | } | ||
- | Write-Log " | ||
- | Write-Log ' | ||
- | Write-Log '***** END *****' | ||
- | $Label.Text = " | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $Label.Text = ' | ||
- | $Form.Refresh() | ||
- | Start-Sleep -Seconds 5 | ||
- | $Form.Close() | ||
- | exit 3010 | ||
- | </ | ||
- | |||
- | < | ||
- | </ | ||
- | |||
- | < | ||
- | </ |