PowerShell HTML Element Variable


I'm trying to capture all HTML elements that match a specific string to run through a foreach loop. The first iteration works as intended, but when it hits the foreach the second time I get an access denied error (0x80070005). When I output the variable, its a System._ComObject, but each element is blank.

I've tried manually starting the foreach at the second element in the array and it works fine. It is just losing the variable data somewhere during the function.

What am I missing?

$global:ie = New-Object -com "InternetExplorer.Application"
$global:ie.visible = $true

function RunReport
start-sleep 5

$global:ie.Navigate("link to reporting home page")

$global:ie.Navigate("link to reporting home page")
start-sleep 2

$links = @($global:doc.IHTMLDocument3_getElementsByTagName('div')) | Where-Object {$_.InnerText -like 'Report Name - Batch*'}
$links | foreach {
$link = $_

asked on Stack Overflow Nov 18, 2020 by user2325484

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0