I am trying to write a powershell script that would create a sql file with a list of file names within a given directory appended by a PRINT statement and ":r" command at the beginning of each filename and finished by "GO" at the end of the filename.
Please see below.
PRINT 'C:/Schemas/Admin.sql'
GO
:r "C:/Schemas/Admin.sql"
GO
PRINT 'C:/Schemas/Audit.sql'
GO
:r "C:/Schemas/Audit.sql"
GO
I am able to print out the file names, but I can't seem to figure out how to prefix and suffix each line. This is what I have:
(get-childitem "C:\schemas" -recurse | where {$_.extension -eq ".sql"}).fullname | out-file "C:\powerShell\masterSQL.sql"