Skip to content

New Feature - Clone login with all DB-level permissions included #3864

@nvarscar

Description

@nvarscar

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 -IncludeDBPermissions
    • Copy-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:

  1. Get databases that source login has users in.
  2. Get DB permissions script for each of the users in that list.
  3. Add login creation part if necessary
  4. Replace names from LoginA to LoginB using regex.
  5. Run the statements against the target server

Latest version of dbatools as of writing

  • 0.9.382

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions