locked
Get-WmiObject taking too much time to get executed RRS feed

  • Question

  • Query to get all installed application is taking too much time

    Get-WmiObject -Class win32_product -ComputerName $Computer | Where-Object -FilterScript {$_.Name -match $ApplicationName}

    • Moved by Richard MuellerMVP Wednesday, April 25, 2018 11:12 AM Not a Profile/Recognition question
    Wednesday, April 25, 2018 7:01 AM

All replies

  • This forum is for questions and discussions about the Profile and Recognition system. I will move your question to a better forum.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Wednesday, April 25, 2018 11:12 AM
  • Yes.  That command can be very slow as it validates every program it finds.  Use a filter to return just one application.


    \_(ツ)_/

    Wednesday, April 25, 2018 12:21 PM
  • Hi niravath.pintu,

    Get-WmiObject takes a long time, how to fix? Is a question that comes up regularly.

    When you are query this command on external computers, for each computer is WMI creating a DCOM link, that takes time.

    Use Invoke-Commandinstead, for better performance. If you do not want to use Invoke-Command, then always remote use CIM (Get-CimInstance) instead of WMI to gain speed.

    LINKS:

    CIM vs. WMI CmdLets – Speed comparison

    Use PowerShell to Run WMI Commands on Remote Computers


    Sincerely, Martien van Dijk. Please remember to mark the replies as answers if they help and unmark them if they provide no help. Check out My Blog!





    Wednesday, April 25, 2018 12:29 PM
  • Neither Invoke-Command nor Get-CimInstance will provide noticaeable performance improvements with the class.


    \_(ツ)_/

    Wednesday, April 25, 2018 12:30 PM
  • Win32_product returns every application, which takes a lot of time.  Using sql-like filters:


    # 42 sec locally
    Get-WmiObject win32_product -ComputerName $Computer -filter "name like '%$ApplicationName%'"


    or


    # 26 sec locally
    Get-WmiObject win32_product -ComputerName $Computer -filter "name = '$ApplicationName'"


    # 1 min 26 sec locally
    Get-WmiObject win32_product -ComputerName $Computer |
      Where Name -match $ApplicationName



    EDIT:
    This class is particularly slow:  https://stackoverflow.com/questions/25083520/wmi-select-from-win32-product-takes-a-long-time





    • Proposed as answer by Richard MuellerMVP Wednesday, April 25, 2018 2:14 PM
    • Edited by JS2010 Friday, April 27, 2018 5:39 AM
    Wednesday, April 25, 2018 12:56 PM