Skip to content
Advertisement

Read the sql files by Exclude the list of files from sql table and Execute all the files in a single Transaction using PowerShell

I have not an Expert in power shell. I Need a script/Approch which handles the below requirement.

I have list of files in a folder and the file Names like below.

Also, I have a table in sql server which holds the file Name Information.

TableName: Executedfile with a column FileName.

My requirement is to read the files which is available in the folder but not in the table.

I have to the Read files only:

Now, I Need to Execute these two file in the sequential order under the same Transaction on SQL Server. As I Need to rollback all the transaction if any Error occurred.

As of now I wrote a power shell something below.

Please suggest me some script.

Challenges:

  1. How to read the files in Sequential order as it has leading Zeros. Does the Above `Sort-Object $_.Name ‘ will Sort ?
  2. How to Execute all the list of files under one transaction.

Thanks

Advertisement

Answer

Finally I wrote the Script using SMO Objects to handle the GO Statement and Transactions.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement