KB0085 - Microsoft Patch KB5074596 Must be non-negative and less than the size of the collection.

KB0085 - Microsoft Patch KB5074596 Must be non-negative and less than the size of the collection.

Scope

This article applies only to PSU scripts or apps that are configured to run in a Windows PowerShell environment.

Problem

  1. You have a known working app or script in PSU that uses Invoke-WebRequest (without -UseBasicParsing) in a Windows PowerShell 5.1 environment.
  2. The app or script stopped working on or about December 9th, 2025.
  3. Microsoft patch KB5074596 has been installed on the PSU server node.
  4. In the app or script log you observe 'Index was out of range. Must be non-negative and less than the size of the collection.'  (example below).


Root Cause

Microsoft released KB5074596 on December 9th which adds a confirmation prompt to the Windows PowerShell Invoke-WebRequest cmdlet (when the -UseBasicParsing parameter is absent).

Workaround #1

The best workaround is to apply the -UseBasicParsing parameter to all invocations of Invoke-WebRequest within your PSU apps and scripts.

Workaround #2

If the -UseBasicParsing parameter breaks your code then you must be HTML DOM parsing. As per Microsoft's guidance, HTML DOM parsing non-interactively (i.e. without explicit human consent) is no longer allowed. However, as a last resort you could try modifying your code to use the InternetExplorer.Application COM object. This is your only recourse left. Below is a working example of how to convert such code.



$invoked = Invoke-WebRequest -Uri 'https://microsoft.com'
$invoked.ParsedHtml.getElementsByClassName('c-uhf-nav-link') | Where-Object { $_.OuterText -eq 'Copilot' } | Select-Object -ExpandProperty href


New code using the InternetExplorer.Application COM object to do the same


$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $false
While ($ie.Busy -or $ie.ReadyState -ne 4) {
    Start-Sleep -Seconds 1
}
$doc = $ie.Document
$doc.getElementsByClassName('c-uhf-nav-link') | Where-Object { $_.OuterText -eq 'Copilot' } | Select-Object -ExpandProperty href
Notes
Invoke-WebRequest does not have a -Force or -Confirm parameter. You cannot send keystrokes ahead to this cmdlet.

    • Related Articles

    • KB0084 - About Microsoft Windows LAPS and PSU

      Scope This article only applies to scenarios where Microsoft Windows Laps[1] is being used. [1] https://learn.microsoft.com/en-us/powershell/module/laps Details PowerShell Universal will require both the -DecryptionCredential parameter and the ...
    • KB0072 - UDDataGrid expands beyond the size of the screen

      Scope This article applies to users creating apps within PowerShell Universal and using UDDataGrid. Problem The data grid does not have any defined size. It will expand to the size of its container. This could be elements such as the page itself, a ...
    • KB0001 - PSU Uninstall Error: "The setup must update files or services..."

      When attempting to uninstall PowerShell Universal (MSI Install) from Control Panel -> Programs you receive the error: "The setup must update files or services that cannot be updated while the system is running. If you choose to continue, a reboot ...
    • KB0074 - Connecting to PSU API w/Windows Auth

      Scope This article applies only to PSU environments where Windows Authentication[1] is enabled and known to be working[2]. Problem You are not able to interact with the PSU instance using the Invoke-WebRequest PowerShell cmdlet even though logging in ...
    • KB - 1008 Tax/VAT Exempt at checkout

      Scope In this article you will learn how to make a tax-free purchase at checkout. Problem How do you remove the Tax/VAT on an order? Impact Orders will then need to be refunded for tax if processed without the tax deducted. Resolution Follow the ...