I’m trying to figure out how to capture an error message for the following line of PowerShell code (for example, if the user running the script doesn’t have permission to read the file):
[IO.File]::ReadAllText("C:\[test].txt")
With Get-Content, I can simply specify the ErrorAction and ErrorVariable parameters. This does not seem to be the case with the above line of code.
Thanks!
Use a try…catch block