Often, there is a request to replicate permission to a new hire or team member using an existing user. Typically, I prefer to use Active directory groups manage permissions for team members.
However, if your SQL instance has native SQL user accounts, you cant easily maintain similar permissions among team members. Here is a way to do that using dbatools. Credit goes to Claudio Silva
$sqlInstance = "SQLSERVER01" $existingUser = "<srcUser>" $newUser = "<newUser>" $ExportedUser = Export-DbaUser -SqlInstance $sqlInstance -User $existingUser -PassThru $NewUserPermissions = $ExportedUser -replace $($existingUser -replace '\\', '\\'), $newUser # Copy the permission to the clipboard. Paste on your query editor and paste there. $newUserPermissions | Set-Clipboard