.\Script_Table_to_File.ps1 FooServer BarDB 'Foo Table' 'X:\Foo Dir\'
This was merely a personal exersize that got a little bit beyond that. 🙂
Tables and output paths that have spaces in them must be encapsulated in single-tick apostrophes on the command line call.
This script will produce two files in a datestamped subdirectory of the $outroot values (UNC paths will work as well). One script is the table schema, which includes DRI and permissions on the object. The second file is the actual data unloaded from the table in a pipe ("|") delimited format.
### NOTE ###: Once the table has been successfully scripted and unloaded it is dropped.
Currently this script only finds dbo owned objects. I suspect I'll need to re-write a good piece of it to find non-dbo objects....
This script will execute against any version of SQL server that I've tested (2000, 2005 & 2008).