Some of my script not working after updating to PowerShell 5.0

I had perfectly running code before updating to 5.0 for crystal reports. Now, some of my lines are giving me error.
For instance

$report = New-Object CrystalDecisions.CrystalReports.Engine.ReportDocument
# Open Weekly Sales Order Totals... report
$report.Load('C:\Users\.....\....\......XXXX.rpt')

# Update all the tables
foreach($Table in $report.Database.Tables)
{
  $table
  $tli=$Table.LogonInfo
  $li=$tli.ConnectionInfo
  Write-host "location:$($table.location)"
  $li.ServerName=""
  $liDatabaseName=""
  $li.UserID=""
  $li.Password=""
  $Table.ApplyLogOnInfo($tli)
  
  $table.location
 }

I get foreach($Table in $report.Database.Tables)
Missing statement body in foreach loop

Other thing is property ServerName cannot be found on this object.

Hmm… the code you’ve pasted here shouldn’t be giving that error, unless maybe there’s some unprintable character between the “foreach($Table in $report.Database.Tables)” part and the opening curly brace on the next line. Try highlighting the closing parenthesis and the opening curly brace on the next line, deleting that, and retyping that bit, see if it helps.

You’re sure you’re running the powershell with admin rights ?

Whats the execution policy ?

can you highlight just the first lines and run them, not the foreach section. Does that work correctly ?

I have changed the execution policy to ‘Unrestricted’. By the way, I have updated to Windows 10 and it comes with PowerShell 5.0.
I am also getting errors when I try to login to the website. I used to run this code on a daily basis. No mistakes before. The errors that I am getting for the code below
HRESULT : 0x800A01B6
$ie.Document.getElementById(“js-username”).value= “username”

HRESULT : 0x800A01B6
$ie.Document.getElementById(“submit_button”).Click()

# Initiate an internet explorer object
$ie = New-Object -com InternetExplorer.Application
$ie.Visible  = $True
$url = "https://"
$ie.navigate($url)
while($ie.busy){Start-Sleep 1}

# Enter login information
$ie.Document.getElementById("js-username").value= "username"
$ie.Document.getElementById("password_field").value = "password"

$ie.Document.getElementById("submit_button").Click()

If you do this:

$ie.Document | Get-Member -Name getElementById

Do you get anything back? It looks like there’s no method present with the name getElementById on your code.

Yes, I do get back the member type and the definition

From what I understand… Internet Explorer has elevated security controls in Windows 10. The solution is to use “IHTMLDocument3_getElementById”, “IHTMLDocument3_getElementsByName” or “IHTMLDocument3_getElementsByTagName” instead. Although these methods aren’t as straight forward when interacting with elements that are linked to Java script…

On a hunch, are you pasting these scripts into the console?