the Get-SharePointInstall function takes a long time to process because it is using the wim (or cim) win32_products class. According to mister google this class should be avoided.
Explanation here:
https://sdmsoftware.com/group-policy-blog/wmi/why-win32_product-is-bad-news/
_When you query this class, the way the provider works is that it actually performs a Windows Installer “reconfiguration” on every MSI package on the system as its performing the query_
and here:
http://gregramsey.net/2012/02/20/win32_product-is-evil/
_even though you called a basic query of the Win32_Product class, you actually performed a consistency check of each installation._
in my case I replaced this line
if (Get-CimInstance -ClassName Win32_Product -Filter "Name like 'Microsoft SharePoint Server%'")
with this:
if(Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* ) #| where-Object {$_.DisplayName -like "Microsoft SharePoint Server*"}
Explanation here:
https://sdmsoftware.com/group-policy-blog/wmi/why-win32_product-is-bad-news/
_When you query this class, the way the provider works is that it actually performs a Windows Installer “reconfiguration” on every MSI package on the system as its performing the query_
and here:
http://gregramsey.net/2012/02/20/win32_product-is-evil/
_even though you called a basic query of the Win32_Product class, you actually performed a consistency check of each installation._
in my case I replaced this line
if (Get-CimInstance -ClassName Win32_Product -Filter "Name like 'Microsoft SharePoint Server%'")
with this:
if(Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* ) #| where-Object {$_.DisplayName -like "Microsoft SharePoint Server*"}