Some of my script not working after updating to PowerShell 5.0

This topic contains 7 replies, has 6 voices, and was last updated by  Lawrence Gulliver 6 months, 4 weeks ago.

  • Author
  • #37937

    Korhan Tezel

    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
    # Update all the tables
    foreach($Table in $report.Database.Tables)
      Write-host "location:$($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.

  • #37942

    Dave Wyatt

    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.

  • #37953

    Arie H

    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 ?

  • #37954

    Korhan Tezel

    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

    # Initiate an internet explorer object
    $ie = New-Object -com InternetExplorer.Application
    $ie.Visible  = $True
    $url = "https://"
    while($ie.busy){Start-Sleep 1}
    # Enter login information
    $ie.Document.getElementById("js-username").value= "username"
    $ie.Document.getElementById("password_field").value = "password"
  • #37956

    Richard Diphoorn

    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.

  • #37958

    Korhan Tezel

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

  • #84733


    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..

  • #84815

    Lawrence Gulliver

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

You must be logged in to reply to this topic.