Some of my script not working after updating to PowerShell 5.0

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Korhan Tezel Korhan Tezel 1 year, 2 months ago.

  • Author
  • #37937
    Profile photo of Korhan Tezel
    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
    Profile photo of Dave Wyatt
    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
    Profile photo of Arie H
    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
    Profile photo of Korhan Tezel
    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
    Profile photo of Richard Diphoorn
    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
    Profile photo of Korhan Tezel
    Korhan Tezel

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

You must be logged in to reply to this topic.