Created
September 8, 2020 18:02
-
-
Save alevyinroc/e7d6846946e80ec4f7552f556ecb819c to your computer and use it in GitHub Desktop.
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
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