Slow to paste into console

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Aaron Aaron 2 weeks ago.

  • Author
    Posts
  • #70295
    Profile photo of Aaron
    Aaron
    Participant

    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

  • #70297
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    Aaron, the answer is 🙂

    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()
    
  • #70300
    Profile photo of Aaron
    Aaron
    Participant

    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

  • #70303
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    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.

  • #70304
    Profile photo of Aaron
    Aaron
    Participant

    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

You must be logged in to reply to this topic.