I am new to PowerShell. When trying to write a simple script that deletes the contents of a folder and then fills it with files copied from a different folder, I always get
After this error (and assuming at that point in it the most recent error):
$error[0] | fl * -force
will expand the details of the error and exception. That should give you more information.
Another thing to do is to switch on verbose logging
$VerbosePreference = "Continue"
to get more details about specifically what operation is being performed when the error occurs.
Finally PowerShell ISE includes a debugger which allows you to step through your script.