0

I'm trying to use a PowerShell script to open IE and login to an intranet site. The script will open IE and load the page but I am getting the following error:

You cannot call a method on a null-valued expression.
At D:\Admin Programs\Bartender\Print Portal Logon Scripts\DahliaPPLogonv2.ps1:9 char:1
+ $usernamefield = $ie.Document.getElementByID('UserName')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The property 'value' cannot be found on this object. Verify that the property
exists and can be set.
At D:\Admin Programs\Bartender\Print Portal Logon Scripts\DahliaPPLogonv2.ps1:10 char:1
+ $usernamefield.value = 'jbob'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The errors repeat for each variable and I cannot figure out why. Full script is below.

# Create an Internet Explorer object
$ie = New-Object -ComObject 'InternetExplorer.Application'
$ie.Visible= $true # Make it visible
# Open website
$ie.Navigate("http://bws01/BarTender/Account/Login") 
#Wait till webpage is loaded
while ($ie.Busy -eq $true) {Start-Sleep -Seconds 5;}
# Feed credentials to the input fields on the web page
$usernamefield = $ie.Document.getElementByID('UserName')
$usernamefield.value = 'jbob'
$passwordfield = $ie.Document.getElementByID('Password')
$passwordfield.value = "123456"
$chk = $ie.Document.getElementById("RememberMe").Checked = $true 
$submit = $ie.Document.getElementById("LogonPageSubmitButton").Click()
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
EddieC
  • 1
  • 1
  • The 1st error implies that `$ie.Document` is `$null`. The `.value`-related errors are just follow-on errors. – mklement0 Apr 06 '17 at 03:03
  • Figured it out, it is an issue with IE security http://stackoverflow.com/questions/13869518/powershell-ie9-comobject-has-all-null-properties-after-navigating-to-webpage/14996243#14996243 – EddieC Apr 06 '17 at 15:23
  • Glad to hear it; looks like the linked answer is an exact duplicate of your question, so I suggest deleting this one, given that there are no answers here. – mklement0 Apr 06 '17 at 15:34

0 Answers0