{"action":"opened","issue":{"url":"https://api.github.com/repos/PSAppDeployToolkit/PSAppDeployToolkit/issues/112","labels_url":"https://api.github.com/repos/PSAppDeployToolkit/PSAppDeployToolkit/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/PSAppDeployToolkit/PSAppDeployToolkit/issues/112/comments","events_url":"https://api.github.com/repos/PSAppDeployToolkit/PSAppDeployToolkit/issues/112/events","html_url":"https://github.com/PSAppDeployToolkit/PSAppDeployToolkit/issues/112","id":115662869,"number":112,"title":"Error in function Test-MSUpdates when no update left in history","user":{"login":"HermannGaetan","id":11949210,"avatar_url":"https://avatars.githubusercontent.com/u/11949210?v=3","gravatar_id":"","url":"https://api.github.com/users/HermannGaetan","html_url":"https://github.com/HermannGaetan","followers_url":"https://api.github.com/users/HermannGaetan/followers","following_url":"https://api.github.com/users/HermannGaetan/following{/other_user}","gists_url":"https://api.github.com/users/HermannGaetan/gists{/gist_id}","starred_url":"https://api.github.com/users/HermannGaetan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HermannGaetan/subscriptions","organizations_url":"https://api.github.com/users/HermannGaetan/orgs","repos_url":"https://api.github.com/users/HermannGaetan/repos","events_url":"https://api.github.com/users/HermannGaetan/events{/privacy}","received_events_url":"https://api.github.com/users/HermannGaetan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-07T12:30:13Z","updated_at":"2015-11-07T12:30:13Z","closed_at":null,"body":"in some circumstances, you have to clean Windows updates history.\r\nIn that case, function Test-MSUpdates will fail if you try to test if a specific update is installed and an error is fired. Additionaly, the script doesn't continue, because no continueOnError is defined in this function.\r\n\r\nPSAppDeployToolkit 3.6.7:\r\n```powershell\r\n\t\t[int32]$UpdateHistoryCount = $UpdateSearcher.GetTotalHistoryCount()\r\n\t\t[psobject]$UpdateHistory = $UpdateSearcher.QueryHistory(0, $UpdateHistoryCount) |\r\n\t\t\t\t\t\tSelect-Object -Property 'Title','Date',\r\n\t\t\t\t\t\t\t\t\t\t\t\t@{Name = 'Operation'; Expression = { Switch ($_.Operation) { 1 {'Installation'}; 2 {'Uninstallation'}; 3 {'Other'} } } },\r\n\t\t\t\t\t\t\t\t\t\t\t\t@{Name = 'Status'; Expression = { Switch ($_.ResultCode) { 0 {'Not Started'}; 1 {'In Progress'}; 2 {'Successful'}; 3 {'Incomplete'}; 4 {'Failed'}; 5 {'Aborted'} } } },\r\n\t\t\t\t\t\t\t\t\t\t\t\t'Description' |\r\n\t\t\t\t\t\tSort-Object -Property 'Date' -Descending\r\n\t\tForEach ($Update in $UpdateHistory) {\r\n\t\t\tIf (($Update.Operation -ne 'Other') -and ($Update.Title -match $KBNumber)) {\r\n\t\t\t\t$LatestUpdateHistory = $Update\r\n\t\t\t\tBreak\r\n\t\t\t}\r\n\t\t}\r\n\t\tIf (($LatestUpdateHistory.Operation -eq 'Installation') -and ($LatestUpdateHistory.Status -eq 'Successful')) {\r\n\t\t\tWrite-Log -Message \"Discovered the following Microsoft Update: `n$($LatestUpdateHistory | Format-List | Out-String)\" -Source ${CmdletName}\r\n\t\t\t$kbFound = $true\r\n\t\t}\r\n```\r\n\r\nFix:\r\n```powershell\r\n\t\t[int32]$UpdateHistoryCount = $UpdateSearcher.GetTotalHistoryCount()\r\n\t\tif ($UpdateHistoryCount -gt 0) {\r\n\t\t\t[psobject]$UpdateHistory = $UpdateSearcher.QueryHistory(0, $UpdateHistoryCount) |\r\n\t\t\t\t\t\t\tSelect-Object -Property 'Title','Date',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t@{Name = 'Operation'; Expression = { Switch ($_.Operation) { 1 {'Installation'}; 2 {'Uninstallation'}; 3 {'Other'} } } },\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t@{Name = 'Status'; Expression = { Switch ($_.ResultCode) { 0 {'Not Started'}; 1 {'In Progress'}; 2 {'Successful'}; 3 {'Incomplete'}; 4 {'Failed'}; 5 {'Aborted'} } } },\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t'Description' |\r\n\t\t\t\t\t\t\tSort-Object -Property 'Date' -Descending\r\n\t\t\tForEach ($Update in $UpdateHistory) {\r\n\t\t\t\tIf (($Update.Operation -ne 'Other') -and ($Update.Title -match $KBNumber)) {\r\n\t\t\t\t\t$LatestUpdateHistory = $Update\r\n\t\t\t\t\tBreak\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tIf (($LatestUpdateHistory.Operation -eq 'Installation') -and ($LatestUpdateHistory.Status -eq 'Successful')) {\r\n\t\t\t\tWrite-Log -Message \"Discovered the following Microsoft Update: `n$($LatestUpdateHistory | Format-List | Out-String)\" -Source ${CmdletName}\r\n\t\t\t\t$kbFound = $true\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tWrite-Log -Message \"No Microsoft Update in update history\" -Source ${CmdletName}\r\n\t\t}\r\n```"}}