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

Conversation

@sqllensman
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

commented Aug 10, 2019

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

@sqllensman

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Member

commented Aug 10, 2019

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

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Member

commented Aug 10, 2019

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

This comment has been minimized.

Copy link
Contributor Author

commented Aug 12, 2019

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

@potatoqualitee

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

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

image

@sqllensman

This comment has been minimized.

Copy link
Contributor Author

commented Aug 13, 2019

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

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

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

@sqllensman

This comment has been minimized.

Copy link
Contributor Author

commented Aug 13, 2019

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

This comment has been minimized.

Copy link
Member

commented Aug 13, 2019

ohhh good call, i wouldnt have known

@potatoqualitee

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

looking great thank you!

@potatoqualitee potatoqualitee merged commit 066c211 into sqlcollaborative:development Aug 14, 2019

1 check passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@sqllensman sqllensman deleted the sqllensman:SqlSat866 branch Aug 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.