You have a typo on the last line, =path should be -path (or you can omit it altogether). To avoid the "header" line, remove format-table, you should never be using this if you want to perform any additional actions with the output, such as export it to CSV. You can also use the -nti switch to remove some additional overhead in the exported CSV. You're also exporting each individual entry to a CSV, thus effectively overwriting the output each time. Use the -Append switch to remedy that. Lastly, spend some time looking at the cmdlet help and the thousands of articles online showing how to work with it. Getting the basics will help you immensely going forward.