Skip to content

Instantly share code, notes, and snippets.

@alevyinroc
Created September 8, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alevyinroc/e7d6846946e80ec4f7552f556ecb819c to your computer and use it in GitHub Desktop.
Save alevyinroc/e7d6846946e80ec4f7552f556ecb819c to your computer and use it in GitHub Desktop.
import-module dbatools;
$SrcInstance = "flexo\sql17";
$DstInstance = "flexo\sql19";
$UserPassword = 'P@$$w0rd' | ConvertTo-SecureString -AsPlainText -Force;
$DBName = "UserPermTest";
$DstUserScriptPath = "C:\sql\Backup\Sql19Users.sql";
# Backup the databases
$Sql17Backup = Backup-DbaDatabase -SqlInstance $SrcInstance -Database $DBName -Path 'C:\sql\Backup\FLEXO$SQL17';
$Sql19Backup = Backup-DbaDatabase -SqlInstance $DstInstance -Database $DBName -Path 'C:\sql\Backup\FLEXO$SQL19';
# Export the users on the destination
$ScriptOption = New-DbaScriptingOption;
$ScriptOption.IncludeDatabaseContext = $false;
$ScriptOption.IncludeIfNotExists = $true;
if (Test-Path -path $DstUserScriptPath -PathType Leaf) {
Remove-Item -Path $DstUserScriptPath;
}
Export-DbaUser -SqlInstance $DstInstance -Database $DBName -ScriptingOptionsObject $ScriptOption -FilePath $DstUserScriptPath | Out-Null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment