Share via

InvalidOperation: Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'indexOf'.

randomfox 0 Reputation points
2025-03-29T22:34:39.9033333+00:00

I'm trying to learn here so bare with me.

All i was trying to do was run the following:

[ADMIN]:PS C:\Windows\System32> update-wingetsoftware -all

Which returned:

Getting winget upgrades ...
Upgrades available: 1 
InvalidOperation: Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'indexOf'. Upgrades selected: 0
Done.


I can't find anything helpful online, I only find articles on the error with different method names, and can't figure out how to relate them to my issue.

Any help would be appreciated.

Here's this in case relevant:

[ADMIN]:PS C:\Windows\System32> get-module | format-table -property ModuleType, Version, Name

ModuleType Version  Name
---------- -------  ----
    Script 1.2.2    LocalUsers
    Script 4.8.5    Logging
  Manifest 3.1.0.0  Microsoft.PowerShell.Management
  Manifest 3.1.0.0  Microsoft.PowerShell.Utility
    Binary 1.10.340 Microsoft.WinGet.Client
  Manifest 1.0.4.0  Microsoft.WinGet.CommandNotFound
    Script 1.4.8.1  PackageManagement
    Script 2.2.5    PowerShellGet
    Script 2.3.6    PSReadLine
    Binary 2.2.1.5  PSWindowsUpdate
    Script 0.1.0    Scripts
    Script 1.9.1    TableUI
    Script 1.0.2    TextTable
    Binary 1.1.0    WindowsConsoleFonts
    Script 1.12.0   WinGet-Essentials
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Marcin Policht 87,815 Reputation points MVP Volunteer Moderator
    2025-03-29T23:11:37.4+00:00

    You're running update-wingetsoftware -all, but it looks like the function is failing with an "indexOf" method invocation error on a PSCustomObject. This likely means that the script or function update-wingetsoftware is trying to call .indexOf() on an object that doesn't support it (likely a PowerShell object, not a string or array).

    1. Check what update-wingetsoftware is update-wingetsoftware is not a built-in PowerShell command, so it's likely coming from one of your installed modules. Check where it's defined by running

    Get-Command update-wingetsoftware -ErrorAction SilentlyContinue
    
    • If it returns a path, the function is likely in a script file.
    • If it returns a module name, you can inspect it using:
        Get-Module -Name <module_name> | Select-Object -ExpandProperty Path
      

    2. Check the function code

    If update-wingetsoftware is a function, you can retrieve its definition:

    Get-Content Function:\update-wingetsoftware
    

    This will show you the code, allowing you to find where .indexOf() is being called incorrectly.

    3. Manually upgrade winget apps As a workaround, try updating apps manually using:

    winget upgrade --all
    

    or, if you're using the WinGet PowerShell module:

    Get-WinGetPackage -Upgrade | ForEach-Object { Start-WinGetPackageUpgrade -Id $_.Id }
    

    4. Ensure your WinGet module is up to date You have Microsoft.WinGet.Client version 1.10.340, but there might be a newer version. Update it using:

    winget upgrade Microsoft.WinGet.Client
    

    or reinstall:

    winget install Microsoft.WinGet.Client
    

    5. Check if another script is interfering Since you have WinGet-Essentials (1.12.0) installed, the function might come from there. Try disabling that module and running update-wingetsoftware again:

    Remove-Module WinGet-Essentials -Force
    update-wingetsoftware -all
    
    • If update-wingetsoftware is from a module, check for updates to that module:
        Update-Module <module_name>
      
    • If the error is in the script, replace .indexOf() with .Contains() or another valid method for PowerShell objects.

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.