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:
What am I doing wrong and how do I fix it?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With