Created
January 22, 2026 15:41
-
-
Save ghotz/a89ed5136c4d1c109387f0e4ead70e9f to your computer and use it in GitHub Desktop.
Backup permissions before deleting logins and users
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
| $instance = 'localhost' | |
| $logins = 'group1','group2' | |
| foreach ($login in $logins) | |
| { | |
| Write-Output "Processing $login" | |
| #$file = "C:\temp\backup-$($login.Replace('\','_')).sql" | |
| #Export-DbaLogin -SqlInstance $instance -Login $login -FilePath $file -ObjectLevel | |
| Remove-DbaDbUser -SqlInstance $instance -User $login -Force | |
| Remove-DbaLogin -SqlInstance $instance -Login $login -Force -Confirm:$false | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment