In Powershell, I frequently use a StreamReader to iterate over files and read/manipulate text. Instead of constantly having to type a script similar to:
## StreamReader setup / file availability check
try {
## Create Stream Reader
$readStream = [System.IO.StreamReader]::new($Path)
## Do stuff ...
} finally {
$readStream.close()
}
How can I make the entire setup/open/close process into a function that I can call whenever I need to automate the 'Do Stuff' portion of my above code? I am aware of how to make functions but I cant figure out how to turn this into a usable function so I only have to write it and edit it once but can use many times.