Scripting

PowerShell Exception 0x800A01B6 while using getElementsByTagName, getElementsByName or getElementByID

Recently, I have started writing automation scripts to automate IE websites and make use of the com-object “InternetExplorer.Application” to automate an internet explorer session.

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

$ie.Navigate($IURL)
while ($ie.Busy) {
  [System.Threading.Thread]::Sleep(10)
}

Using $ie.Document.getElementsByTagName(“Input”) enables me to enumerate the form fields and buttons. This works for the first website that I am visiting. If I then navigate to another site, $xe.Document.getElementsByTagName(“Input”) generates the following exception:


Exception from HRESULT: 0x800A01B6
At line:1 char:1
+ $Global:ie.Document.getElementsByTagName("Input")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : OperationStopped: (:) [], NotSupportedException
 + FullyQualifiedErrorId : System.NotSupportedException

Workaround

Always use the following methods instead of the native ones:


IHTMLDocument3_getElementsByTagName
IHTMLDocument3_getElementsByName
IHTMLDocument3_getElementByID

Example


$ie = New-Object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.silent = $true
$ie.Navigate($IURL)
while ($ie.Busy)
{
[System.Threading.Thread]::Sleep(10)
}
$ie.Document.IHTMLDocument3_getElementsByTagName("Input") $ie.Navigate($IURL2) while ($ie.Busy)
{
[System.Threading.Thread]::Sleep(10)
}
$ie.Document.IHTMLDocument3_getElementsByTagName("Input")

Advertisements
Windows

Securing Built-in Administrator Accounts in Active Directory

All of us know that the built-in Administrator account cannot be locked out and it has the following behaviour:

  1. The authentication package ignores the Lockout attribute and returns a failed login
  2. The Lockout attribute is reset upon successful login.

If you want to secure this account, head to the following link:

https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-best-practices/appendix-d–securing-built-in-administrator-accounts-in-active-directory

Scripting

Which is the fastest tool to search through Windows Event Logs?

If you need to comb through tons of Windows Event Logs especially Security logs, it may take a long time due to the size. There are many different tools/scripts out there which can search the logs but each one has its own strengths and weaknesses.

I’ve done some comparison and the champion turns out to be wevtutil.exe tool.  It’s many many times a lot faster than any other tools.  Do try it out!