SCOM Invoke-WebRequest allElements powershell discovery

Fursel 341 Reputation points
2023-02-15T18:56:29.9766667+00:00

Hello,

I am trying to make a discovery for objects on website but when trying go through all elements on the page it doesn't give me any results even though script works fine on server where monitoring agent is making it while running it from ISE or Powershell. Healthservice is running as local system but also trying to run it as system it works fine from Powershell directly but not with SCOM Discovery.

So basically there is:

$site = Invoke-WebRequest -Uri 'https://somesite.com' -> this returns some parts of the data, also when trying to export-clixml is not complete

$site.allElements -> this doesn't return any data, looks like invoke-webrequest behave like with -usebasicparsing

Maybe someone had this issue before and resolved it somehow ?

System Center Operations Manager
System Center Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,602 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Fursel 341 Reputation points
    2023-02-15T20:49:22.8533333+00:00

    Worked with :

    $HTML = New-Object -Com "HTMLFile"
    
    try {
        # This works in PowerShell with Office installed
        $html.IHTMLDocument2_write($site.content)
    }
    catch {
        # This works when Office is not installed    
        $src = [System.Text.Encoding]::Unicode.GetBytes($site.content)
        $html.write($src)
    }
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

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