Cody Konior shows us how to create a SQL Server bulk insert format file using Powershell:
Don’t forget there are a few minor security considerations:
- Your login needs Administer Bulk Operations permission.
- Your AD account needs access to the file (and possibly delegation enabled for remote shares)
- Or if using an SQL login the database engine service account needs access to the file.
Anyway now that we have the data in table format without worrying about ordering or duplicate column names, we can much more easily manipulate it and store it into the database.
I remember creating a couple of these by hand, and that was no fun. I never created enough to get the hang of the syntax or to want to automate the process, but at least I know where to look if I ever have to do this again.