This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Invoke-WebRequest Powershell HTML Parsing

I am working on a webpage login monitor on a page that has three fields. I have been able to get it to work outside of Orion, but when trying to create a powershell monitor I get the following error:  I have found that it is due to the fact that '-UseBasicParsing' isnt pulling the form or the inputfields. Has anyone figured out a way around this? Is IE supposed

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
At line:3 char:6
+ $r = Invoke-WebRequest -Uri ($loginURL + '
logonform.jsp')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

So, I add '-UseBasicParsing' and then all I get is this:

Cannot index into a null array.

At line:5 char:1

+ $form = $r.Forms[0];

+ ~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (:) [], RuntimeException

+ FullyQualifiedErrorId : NullArray

I have found that it is due to the fact that '-UseBasicParsing' isnt pulling the form or the inputfields. Has anyone figured out a way to get this to work? These are based on IE. Is IE usable for powershell monitors or does application monitoring go some other route. Just to make sure I brought up IE on the poller and made sure that the sites I am trying to monitor with this are part of the trusted sites.

Here is the source code:

$loginbase = '<input omitted>'
$loginURL
= $loginbase + '<input omitted>'
$r
= Invoke-WebRequest -Uri ($loginURL + 'logonform.jsp') -UseBasicParsing
return $r;

$form
= $r.Forms[0];

return $form

$form
.Fields['aps'] = '<input omitted>';
$form
.Fields['usr'] = '<input omitted>';
$form
.Fields['pwd'] = '<input omitted>';

$r
= Invoke-WebRequest -Uri ($loginURL + $form.Action) -Method POST -Body $form.Fields;

if ($r.Content -match 'setup()') {

  
if ($r.StatusCode -eq 200) {

  
Write-Host 'Message:' $r.StatusDescription;
  
Write-Host 'Statistic:' $r.StatusCode;
  
Exit 0;
  
}

  
Write-Host 'Message:' $r.StatusDescription;
  
Write-Host 'Statistic:' $r.StatusCode;
  
Exit 1;
}

Write-Host 'Message: Did not login';
Write-Host 'Statistic: 1';
Exit 1;

  • You'll want to disable IE's first-launch wizard. I've had issues with that in the past when i came to powershell monitors. The Solarwinds services run as 'Local System' by default and there isn't a way to start the first-launch wizard without editing the registry.

    Using Group Policy Editor

    Using Group Policy Editor is probably the best method, because it can be used either locally, on one computer, or in an Active Directory environment by utilizing the GPO power.

    1. Press Start button + R (the Run command), type gpedit.msc and press Enter to launch the Group Policy Editor.

         Note: In an Active Directory environment, open gpmc.msc and either edit an existing GPO, or create a new one and link it to the domain level, or to an OU of your choice.

    2. In the left pane, If you're Solarwinds server is still running services as 'Local System' then first the first option below. If your services are running as a local windows user account or AD account choose the second option.

    • 'Local System': expand Computer Configuration > Administrative Templates > Windows Components > Internet Explorer.
    • 'Local or AD service account: expand User Configuration > Administrative Templates > Windows Components > Internet Explorer.

    3. On the right pane, double-click on “Prevent running First Run wizard". A new settings window will open up.

    4. Set the value to “Enabled”.

    5. In the options section you must choose one of the two options from the drop-down menu:

    • Go directly to “Welcome To IE” page
    • Go directly to home page

         You need to choose one of the two, otherwise the configuration will not work.

         The first option configures IE to skip the Welcome screen and go directly to your home page, whatever it is.

         The second option configures IE to skip the Welcome screen and and go to the “Welcome to Internet Explorer” page directly.

    6. Click Apply to save the settings then click OK and close the Group Policy Editor window.

    7. Press Start button + R (the Run command) and type gpupdate /force and press Enter to refresh the Group Policy on the computer.

    Source: Andres Cheah: Microsoft: How To Disable Internet Explorer First Run Welcome Screen Pop Up

  • Thank you! I had been messing around with the IE settings for the AD service account. I didnt even think about it running as Local System