1

Bit of an odd one here. I have several Powershell scripts I've been using for years that end in a pause with the following command:

Write-Host "Done.";
Write-Host "Press any key to continue";
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown");

The main idea being to prevent the window closing and allowing me to review outputs, like AD group memberships and such. We've recently updated our servers to Powershell 5.1 and since the update the pause has been occurring in the wrong place. Instead of the script outputting the results and then pausing, it's now doing the opposite. It seems to be waiting for the script to finish and then providing the results from the script.

Is this a design change that has been put in place in Powershell? If so, is there a new command that will let me get these scripts back to business as usual?

KOL2024
  • 11
  • 3
  • 1
    in PoSh v3 [or perhaps v4] the devs added a delay to anything that uses the output/success stream. it's about 300 ms ... but the pause will bring _everything_ to a halt. your pause uses _direct_ screen access, but the output stream gets to the screen _indirectly_. you will likely need to find a way to force your output stream to go to the screen _immediately_. one method is to add `| Out-Host` to the end of anything you want displayed _right freaking now_. [*grin*] ///// there is a builtin `pause` function, but i think that uses host writes ... so it likely will not help. – Lee_Dailey Nov 06 '19 at 02:51
  • Good points, @Lee_Dailey, except that the delay only applies to implicitly applied `Format-Table`, and there only to output types that have no predefined table-formatting data - see the linked post and https://stackoverflow.com/a/43691123/45375 for the full story. – mklement0 Nov 06 '19 at 05:43
  • @mklement0 - thank you for the extra info. [*grin*] in my limited experience, nearly everything has that awkward delay when sent from the output stream to the display system. i guess i have just been "lucky" ... – Lee_Dailey Nov 06 '19 at 16:13

0 Answers0