Export-DbaUser - Add schema ownership to exported scripts#10275
Draft
andreasjordan wants to merge 5 commits intodevelopmentfrom
Draft
Export-DbaUser - Add schema ownership to exported scripts#10275andreasjordan wants to merge 5 commits intodevelopmentfrom
andreasjordan wants to merge 5 commits intodevelopmentfrom
Conversation
This change adds schema ownership information to the output of Export-DbaUser. Previously, if a user owned a schema, that ownership was not included in the exported script, causing issues when recreating security contexts. The implementation: - Iterates through schemas owned by the user - Generates ALTER AUTHORIZATION statements for each owned schema - Supports the -Template parameter for placeholder substitution - Follows dbatools style guidelines (double quotes, proper formatting) Tests added: - Verify schema ownership is exported for users that own schemas - Verify template placeholders work correctly for schema ownership Fixes #9458 (do Export-DbaUser) Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
…458-20251128-1635
Collaborator
Author
|
@claude we need to exclude the schems owned by @("sa", "dbo", "information_schema", "sys") like in lines 388 and 479. |
|
Claude finished @andreasjordan's task in 39s —— View job Tasks
DoneAdded the exclusion filter to the foreach ($schema in $db.Schemas | Where-Object { $_.Owner -eq $dbuser.Name -and @("sa", "dbo", "information_schema", "sys") -notcontains $_.Name }) {This excludes schemas named |
Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
Collaborator
Author
|
@claude we need to exclude the schema "guest" as well. |
|
Claude finished @andreasjordan's task in 33s —— View job Tasks
DoneAdded foreach ($schema in $db.Schemas | Where-Object { $_.Owner -eq $dbuser.Name -and @("sa", "dbo", "information_schema", "sys", "guest") -notcontains $_.Name }) { |
Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds schema ownership information to the output of Export-DbaUser.
Previously, if a user owned a schema, that ownership was not included in the exported script, causing issues when recreating security contexts.
Changes:
Fixes #9458
Generated with Claude Code