Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 2
    Great! Thanks! To my shame, I must confess that I develop in powershell and did not think about using the .net classes for this. [I hope that will not go any further :-)] Commented Dec 28, 2014 at 14:49
  • 1
    Nice answer. For the curious, here's the MSDN link to the File::Open method detailing the parameters of the call (specifically, the last argument, 'None', declines sharing the file with any other threads/processes - and likewise, provisions exist to lock the file for read/write only, or a combination thereof). Commented Dec 28, 2014 at 20:23
  • 1
    @moab The file is closed and the handle released at the end.
    – Dan
    Commented Dec 28, 2014 at 22:43
  • 3
    Note the $host.UI.RawUI.ReadKey(...) will fail in PowerShell ISE as ReadKey is not implemented for the ISE. The workaround is [void](Read-Host 'Press Enter to continue'). Not exactly the same as the user has to press Enter rather than any key. However, good enough for most purposes. The workaround came from this blog post: jeffwouters.nl/index.php/2016/06/…
    – Simon Elms
    Commented Sep 7, 2016 at 4:10