This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
userspace:windows_updates_-_powershell [2017/03/02 09:34] trabs-ol |
userspace:windows_updates_-_powershell [2021/08/23 08:37] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Mit diesem Script werden so lange Updates | + | ====== WSUS Updates |
| - | Voraussetzungen: | + | 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: | ||
| + | |||
| + | Getestet unter Windows 7 x64 SP1 | ||
| + | |||
| + | Logging des Scriptes erfolgt in C: | ||
| + | |||
| + | Ordnerstruktur: | ||
| + | |||
| + | CLIENT_DATA | ||
| + | * install-updates.ps1 | ||
| + | * install-updates-once.ps1 | ||
| + | * once64.ins | ||
| + | * setup64.ins | ||
| + | * windows_update_icon.png (nur fürs gute Aussehen) | ||
| + | |||
| + | OPSI | ||
| + | * control | ||
| setup64.ins | setup64.ins | ||
| Line 21: | Line 39: | ||
| DefVar $MinimumSpace$ | DefVar $MinimumSpace$ | ||
| DefVar $ExitCode$ | DefVar $ExitCode$ | ||
| - | |||
| - | DefStringList $Version_List$ | ||
| - | DefVar $Version$ | ||
| Set $LogDir$ = " | Set $LogDir$ = " | ||
| Line 45: | Line 60: | ||
| ShowBitmap " | ShowBitmap " | ||
| - | Message " | + | |
| - | set $Version_List$ = getOutStreamFromSection (" | + | |
| - | set $Version$ = takeString(2, | + | |
| - | + | ||
| - | if ($Version$ < " | + | |
| - | Message " | + | |
| - | opsiServiceCall_Powershell_Setup | + | |
| - | Message " | + | |
| - | ExitWindows / | + | |
| - | else | + | |
| - | Message " | + | |
| - | endif | + | |
| - | + | ||
| - | | + | |
| Message " | Message " | ||
| DosInAnIcon_WindowsUpate | DosInAnIcon_WindowsUpate | ||
| Line 64: | Line 66: | ||
| endif | endif | ||
| - | |||
| - | [DosInAnIcon_PSVersion_check] | ||
| - | powershell.exe $PSVersionTable.PSVersion.Major | ||
| [Files_Install] | [Files_Install] | ||
| CheckTargetPath = " | CheckTargetPath = " | ||
| - | copy -u " | + | copy -u " |
| [DosInAnIcon_WindowsUpate] | [DosInAnIcon_WindowsUpate] | ||
| - | " | + | " |
| - | + | ||
| - | [opsiServiceCall_Powershell_Setup] | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | ] | + | |
| [Sub_check_exitcode] | [Sub_check_exitcode] | ||
| Line 131: | Line 122: | ||
| DefVar $MinimumSpace$ | DefVar $MinimumSpace$ | ||
| DefVar $ExitCode$ | DefVar $ExitCode$ | ||
| - | |||
| - | DefStringList $Version_List$ | ||
| - | DefVar $Version$ | ||
| Set $LogDir$ = " | Set $LogDir$ = " | ||
| Line 155: | Line 143: | ||
| ShowBitmap " | ShowBitmap " | ||
| - | Message " | + | |
| - | set $Version_List$ = getOutStreamFromSection (" | + | |
| - | set $Version$ = takeString(2, | + | |
| - | + | ||
| - | if ($Version$ < " | + | |
| - | Message " | + | |
| - | opsiServiceCall_Powershell_Setup | + | |
| - | Message " | + | |
| - | ExitWindows / | + | |
| - | else | + | |
| - | Message " | + | |
| - | endif | + | |
| - | + | ||
| - | | + | |
| Message " | Message " | ||
| DosInAnIcon_WindowsUpate | DosInAnIcon_WindowsUpate | ||
| Line 174: | Line 149: | ||
| endif | endif | ||
| - | |||
| - | [DosInAnIcon_PSVersion_check] | ||
| - | powershell.exe $PSVersionTable.PSVersion.Major | ||
| [Files_Install] | [Files_Install] | ||
| CheckTargetPath = " | CheckTargetPath = " | ||
| - | copy -u " | + | copy -u " |
| [DosInAnIcon_WindowsUpate] | [DosInAnIcon_WindowsUpate] | ||
| - | " | + | " |
| - | + | ||
| - | [opsiServiceCall_Powershell_Setup] | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | " | + | |
| - | ] | + | |
| [Sub_check_exitcode] | [Sub_check_exitcode] | ||
| Line 222: | Line 186: | ||
| 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 | ||
| </ | </ | ||