Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created January 22, 2026 15:41
Show Gist options
  • Select an option

  • Save ghotz/a89ed5136c4d1c109387f0e4ead70e9f to your computer and use it in GitHub Desktop.

Select an option

Save ghotz/a89ed5136c4d1c109387f0e4ead70e9f to your computer and use it in GitHub Desktop.
Backup permissions before deleting logins and users
$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