Powershell Try Catch IOException DirectoryExist

Question:

I’m using a power shell script to copy some files from my computer to a USB drive. However, even though I’m catching the System.IO exception, I still get the error at the bottom. How do I properly catch this exception, so it shows the message in my Catch block.

Answer:

I don’t suggest actually catching the error in this case. Although that may be the correct action in general, in this specific case I would do the following:

Source:

Powershell Try Catch IOException DirectoryExist by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply