1

i am a beginner all around PowerShell, and my main difficult is that i have the following script and i would like to create a log file from the output of the URL. for now the script is working but i don't know how can i save the browser output to a file. i will need to write the output into new file only in case the file is not created. i try the |Out-File method but nothing happens.

my script:

start "http://myurl"
Start-Sleep -s 5
get-process iexplore | stop-process
get-process powershell | stop-process

this is my php code:

    <?php
/**
 * Created by PhpStorm.
 * User: matant
 * Date: 11/17/2015
 * Time: 1:46 PM
 */
define ('mysql_host','host');
define ('mysql_user','user');
define ('mysql_password','password');
define ('myDB','DBname');


$dblink= mysqli_connect(mysql_host, mysql_user, mysql_password,myDB);


if (!$dblink)
{
    $message = sprintf(
        "Could not connect to local database: %s",
        mysql_error()
    );
    trigger_error($message);
    echo $message;
    return;
}
else{
    echo "connection success"."<br/>";
}
$c_date = date("Y-m-d");
date_default_timezone_set('Asia/Jerusalem');
$c_time = date("h:i:sa");
$query = "UPDATE event SET event_status = '0' WHERE event.event_date < '$c_date' OR '$c_time' >  event.start_time";
$res = mysqli_query($dblink,$query) or die (mysqli_error($dblink));
if(!$res){
    echo $c_time.":failed to update event!"."<br/>";
}
else{
    echo $c_time."  :event updated successfully";
}
$dblink ->close();
?>

for example if the script run successfully i get the message:

 connection success
04:39:36pm :event updated successfully

which this message i would like to be saved into a file.

1
  • 1
    What do you mean with 'browser output'? What information do you want to save? Can you give an example of the output you want in the text file? Commented Nov 17, 2015 at 14:32

1 Answer 1

6

You can use Invoke-WebRequest

Invoke-WebRequest -Uri "http://www.bbc.co.uk" | select -ExpandProperty Content | Out-File test.txt

Sign up to request clarification or add additional context in comments.

5 Comments

i get this error when i replace all my script with your answer: "The term 'Invoke-WebRequest' is not recognized as the name of a cmdlet,..."
Invoke-WebRequest was only added in PowerShell 3.0 - looks like you're still running V2 so won't be able to use this function.
thanks i try it in windows server 2012 and its working thank you.
but my output into the file is : "connection success<br/>04:56:22pm :event updated successfully" there is a way to fit it to the browser?
Do you want to see the message in both a web browser, and in the log file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.