Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the script output itself to the console?

My script outputs itself to the console before then executing the script. This is my code:

for ($i=1; $i -le 1000; $i++) {
    Write-Host "Sending request #$i"
    $request = Invoke-WebRequest "http://localhost/test"



    $random = Get-Random -Minimum 1 -Maximum 5
    Start-Sleep -Seconds $random

}

Which then does this in PowerShell ISE: enter image description here

What am I doing wrong and how do I fix it?

like image 866
user9993 Avatar asked Oct 19 '25 01:10

user9993


1 Answers

This happens when you use PowerShell ISE and run the script without saving it.

Essentially it copies the whole script into the console and then executes it from there.

Once you save it to a file, it will switch to calling the file and it won't display the whole script.

You can see this first hand if your execution policy is set not to execute scripts, because you'll be able to run the script before saving it but not after (until you change execution policy).

like image 158
briantist Avatar answered Oct 22 '25 05:10

briantist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!