Created
June 25, 2019 11:12
-
-
Save roe3p/09c546f553e66c71c1a02153339653a8 to your computer and use it in GitHub Desktop.
Export DB Users using DBATools
This file contains 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
$ServerName = "Myserver.mydomain.co.uk" | |
$OutputPath = "G:\Backups\SRV01Users\" | |
$Dt = Get-Date -f yyyyMMdd #-hhmmss | |
$Databases = Get-DbaDatabase -sqlinstance localhost | |
$Counter = 1 | |
$DBCount = $Databases.Count | |
foreach($Database in $Databases) { | |
$DatabaseName = $Database.Name | |
$Filename = $OutputPath + $dt+"_"+$DatabaseName+".sql" | |
Write-Host "Exporting users for DB: $DatabaseName [$Counter of $DBCount]" -ForegroundColor Green | |
Write-Host "To file: $Filename..." -ForegroundColor Green | |
$Database | Export-DbaUser -Filepath $Filename | |
$Counter++ | |
# Export-DbaUser -SQLInstance $ServerName -Database $DatabaseName -Filepath $Filename | |
} | |
$Filename = $OutputPath + $dt +"_"+$ServerName+".sql" | |
Write-Host "Exporting users for all databases on: $ServerName" -ForegroundColor Green | |
Write-Host "To file: $Filename..." -ForegroundColor Green | |
Export-DbaUser -SQLInstance $ServerName -Filepath $Filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment