Task Scheduler Problems With Powershell

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #5958

    by Lecter at 2012-11-20 00:09:16

    hello.

    Coul you help me.

    The problem is related to this thread: "http]"

    I have the similar problem. We have some scripts. They need to write results in to TXT file...

    $ie = New-Object -com InternetExplorer.Application
    $ie.visible = $false
    $ie.navigate("http://fr/lala.jsp")
    while($ie.busy) {start-sleep 10} sleep 10
    @($ie.Document.getElementsByTagName('input'))[0].click()
    while($ie.busy) {start-sleep 10} sleep 8
    $ie.Document.documentElement.innerHTML | Out-File D:\C\M\Result\M105.txt
    $ie.Quit()
    exit

    I'm attaching the screens how task is set
    [size=150]
    1.[/size]

    a user uploaded image
    [size=150]
    2.[/size]

    a user uploaded image
    [size=150]
    3.[/size]

    a user uploaded image
    [size=150]
    4.[/size]

    a user uploaded image
    [size=150]
    5.[/size]

    a user uploaded image
    [size=150]
    6.[/size]

    a user uploaded image

    Sorrz for french.

    The problem is that script is executed but results sometimes are written in to TXT, sometimes NOT. Sometimes task is running sometimes not.

    I've set "systemuser" but it was not possible to write files to TXT so "it is working" only on our users.

    Could you help me what to do, or what to check and set ?

    As for now it stopped working and it does not save result to TXT file... 🙁

    by DonJ at 2012-11-20 08:53:35

    I'm sorry – I can't follow any of that, mainly because I'm useless with French. You started with a script that uses IE to open a Web page, and then got into task scheduling, and I'm confused. Are you trying to write a script that gets scheduled as a task?

    by Lecter at 2012-11-21 05:11:20

    [quote="DonJ"]I'm sorry – I can't follow any of that, mainly because I'm useless with French. You started with a script that uses IE to open a Web page, and then got into task scheduling, and I'm confused. Are you trying to write a script that gets scheduled as a task?[/quote]

    Hi.

    Sorry for that.
    I'll try to describe everything onece again.

    I wrote a PS script to get specufied HTML code of this webpage and write it to file *.txt on drive D

    $ie = New-Object -com InternetExplorer.Application
    define new object Internet Explorer

    $ie.visible = $false
    IE not visible

    $ie.navigate("http://fr/lala.jsp")

    navigate to "special" webpage

    while($ie.busy) {start-sleep 10} sleep 10
    sleep while it full load

    @($ie.Document.getElementsByTagName('input'))[0].click()
    get in HTMLcode of this page input – button – and click this button to anter next page

    while($ie.busy) {start-sleep 10} sleep 8
    sleep while it load

    $ie.Document.documentElement.innerHTML | Out-File D:\C\M\Result\M105.txt
    get innerHTML in webpage code (it's just text for REPORT) and wrte this text in to *.txt file

    $ie.Quit()
    exit

    quit and exit

    It perfectly works on PS console

    But problems begun when we put it in to scheduler.

    It can work without problems 3 hours than we logoff from this VM and it's stopping to write this code in to *.TXT FILE.

    The same problem happened when we used "systemuser".

    I attached screens how the "TASK" is configured.

    I don't understand why TASK scheduler has problems with executing this PS Scripts. It's saving empty *.TXT files.

    Best Regards
    L

    by DonJ at 2012-11-21 07:18:46

    This *probably* has nothing to do with PowerShell, and more to do with how you're using IE. In order for IE to run, Task Scheduler needs to bring up a full desktop session, and I'm not sure if it's capable of doing that. Task Scheduler is probably fine, and PowerShell is probably fine. It's probably IE that isn't executing properly, and I don't know how to work around that. The IE COM automation object you're using wasn't intended to be used this way.

    If it were me, I might try to reverse-engineer the Web page, and its code, and implement this using Invoke-WebRequest instead. That's a lot of work, but I've always found automating IE to be a very sometimes-works, sometimes-breaks affair.

You must be logged in to reply to this topic.