-
-
Notifications
You must be signed in to change notification settings - Fork 864
New Feature - Clone login with all DB-level permissions included #3864
Copy link
Copy link
Closed
Labels
Description
name: New feature - clone a certain login including all the DB-level permissions 💣
about: Either a new function, or a new switch in New-DbaLogin to get permissions from each database of the source login and apply them to a new login.
Summary of new feature
- Right now there is no certain way of cloning user permissions fully. Sync-DbaLoginPermissions only does so on the login level, using underlying function Update-SqlPermissions, that only covers database level permissions and roles; all the object-level permissions are ignored. There is Export-DbaDbUser, which, if used together with Export-DbaDbLogin and some regex magic, might do the trick. However, I would rather have that functionality built-in into module, as this is one of the most popular questions I get: create new login A with permissions like user B.
- Options to consider:
Get-DbaLogin LoginA | New-DbaLogin LoginB -IncludeDBPermissionsCopy-DbaDbPrivileges -From LoginA -To LoginB(Export-DbaUser -Login LoginA -IncludeLoginScript) -replace 'LoginA','LoginB'
Proposed technical details (if applicable)
This will all come down to the following actions inside a function:
- Get databases that source login has users in.
- Get DB permissions script for each of the users in that list.
- Add login creation part if necessary
- Replace names from LoginA to LoginB using regex.
- Run the statements against the target server
Latest version of dbatools as of writing
- 0.9.382
Reactions are currently unavailable