Slow to paste into console

Hey, this isnt so much a scripting question as a powershell/console question…

When I paste into powershell something like

write-host "hi"
write-host "hi"
write-host "hi"

Each line will take 2 seconds to paste in…but if i paste in something like

{
write-host "hi"
write-host "hi"
write-host "hi"
write-host "hi"
write-host "hi"
write-host "hi"
}

It will paste everything in instantaneously…I’m not sure what the issue is, I was messing with the powershell buffer awhile back but I’m not sure if that’s related

Aaron, the answer is :slight_smile:

Your first example gets executed immediately while your second example creates a transient ScriptBlock which doesn’t get executed just parsed. If you change your second example to the following you should see the same delay.

{
write-host "hi"
write-host "hi"
write-host "hi"
}.Invoke()

I’ve attached a Gif that shows the behavior I’m looking at…

Pasting in a 100 line script can take minutes when it used to take just a second.

The code I’m running in the gif is just:

write-host "hi"
write-host "hi"
write-host "hi"
write-host "hi"

{
write-host "hi"
write-host "hi"
write-host "hi"
}.Invoke()


do{}while(1 -eq 2)
do{}while(1 -eq 2)
if(1 -eq 1){"hi"}

This is what I would expect to see, did this on another PC with the same code: Normal

Thanks, from your images I’ve noticed that you’re testing on different OS versions. “Slow” looks like Win10 and “Normal” like Win7/8. The console implementation is different between Win10 and Win7/8. Additionally, PS v5.x integrates with antimalware engines which most likely affect performance as well if your AV/AM software hooks into that API.

On the other hand pasting large amounts of commands into the console is probably not a common scenario because users should have these in .ps1 files.

Not sure how to help you. Probably best to raise an issue on GitHub (https://github.com/powershell/powershell) to get direct feedback from the PowerShell team.

Yeah, I’m on windows 10 and took a screen shot from a server 2012 R2, not the best comparison but it’s as fast as my PC used to run…

It’s just odd, I may just rebuild, was just curious if someone else had a similar issue and had a quick fix.

Thanks for your help, i’ll try the github before blowing away my pc