Utility to script least permissions required to run script
Hello, I am looking for a utility (maybe in PowerShell?) to analyze a .sql file and a server to determine the least permissions, down at least to the table level, required to run that script (NOT scripting out permissions that exist for a user). My use case is: I have multiple .sql files defining objects I want created each time a reporting copy of a particular database is restored. I'd like to use an active directory account as a SQL Agent proxy to run the scripts, but I'd like to give that account only the permissions it needs to run the scripts, and I would rather not slog through all the files to figure out exactly what those permissions are. I'd also like to be able to swiftly rebuild those permissions if I add more files later. Ideally, it would export a series of GRANT statements. Has anyone come across such a utility? Thanks for your help.