Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to add export functions for Roles #5954

Merged
merged 10 commits into from Aug 14, 2019
Merged

Changes to add export functions for Roles #5954

merged 10 commits into from Aug 14, 2019

Conversation

sqllensman
Copy link
Contributor

@sqllensman sqllensman commented Aug 10, 2019

Type of Change

  • Bug fix (non-breaking change, fixes #)
  • New feature (non-breaking change, adds functionality)
  • Breaking change (effects multiple commands or functionality)
  • Ran manual Pester test and has passed (`.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/sqlcollaborative/appveyor-lab ?
  • Nunit test is included
  • Documentation
  • Build system

Purpose

Add function to export Database and Server Roles

Approach

Adds code that wraps T-SQL scripts that fully generate the Role scripts

This command is based off of John Eisbrener's post "Fully Script out a MSSQL Database Role"
Reference: https://dbaeyes.wordpress.com/2013/04/19/fully-script-out-a-mssql-database-role/

Includes changes to
Get-DbaDbRole to fix issue with offline databases
Get-DbaServerRole to exclude AzureDB's

Used with Permission

Commands to test

Get-DbaDbRole
Get-DbaServerRole
Export-DbaDbRole
Export-DbaServerRole

@wsmelton
Copy link
Member

Export of server roles I can understand, but what purpose would there be in exporting database roles?

@sqllensman
Copy link
Contributor Author

sqllensman commented Aug 10, 2019

Getting the full permissions of a role is not easy via any current process (at least that I am aware of)

This is why the script from John Eisbrener was created

@potatoqualitee
Copy link
Member

thank you so much! your tests are glorious 🌞 💯

Just a few changes needed:

Was testing how far this can go back and found that it needs a try catch around the enumeration of the dbs or unprocessable dbs need to be skipped.

image

2005 was only slightly problematic

image

and 2000 needs to be skipped

image

@sqllensman
Copy link
Contributor Author

sqllensman commented Aug 10, 2019

I will look into the enumeration errors and also issue with SQL 2005 or earlier.
The problem in Roles for Offline databases is actually coming from Get-DbaDbRole so this will need to be adjusted to exclude unprocessable dbs
May take a day as this was done at SQLSaturday Auckland and I won't be home until tomorrow

@wsmelton
Copy link
Member

You will also need to exclude Azure SQL from being passed in since these queries are not supported. You can just add -AzureUnsupported to your Connect-SqlInstance call to handle this one.

@sqllensman
Copy link
Contributor Author

Changes added to exclude unsupported versions and fix problems with offline databases
Also replaced calls to Invoke-SqlQuery with .Query calls

@potatoqualitee
Copy link
Member

So close! You can do -MinimumVersion on Connect-SqlInstance if you can't get it to work.

image

@sqllensman
Copy link
Contributor Author

Do you have more details on where this error is being generated?
I have tried this against multiple SQL Server 2005 instances and cannot reproduce the above error.

The error looks like some issue with Collation differences . What is the collation of SQL2005 instance you are testing against?

@wsmelton
Copy link
Member

I'd also verify what compat-level the database is in (on 80, those queries would not run).

@sqllensman
Copy link
Contributor Author

Thanks @wsmelton
I tested on a 2005 instance and putting a Database into compat-level 70 is able to reproduce the error.
Using compat-level 80 did not cause error but I will restrict to compat-level 90 or higher

@potatoqualitee
Copy link
Member

ohhh good call, i wouldnt have known

@potatoqualitee
Copy link
Member

looking great thank you!

@potatoqualitee potatoqualitee merged commit 066c211 into dataplat:development Aug 14, 2019
@sqllensman sqllensman deleted the SqlSat866 branch August 14, 2019 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants