-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunMigration.ps1
183 lines (122 loc) · 11.9 KB
/
RunMigration.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Param
(
[Parameter(Mandatory=$true)]
[string] $ProjectName = 'LucientMigration',
[Parameter(Mandatory=$true)]
[string] $SQLInstanceListLocation,
[Parameter(Mandatory=$true)]
[string] $ResultOutputPath,
[Parameter(Mandatory=$true)]
[ValidateSet("JSON")]
[string] $OutputFormat,
[Parameter(Mandatory=$true)]
[ValidateSet("SqlServer2016","SqlServerWindows2017","SqlServerWindows2019","AzureSqlDatabase","ManagedSqlServer","All_5")]
[string] $Target,
[Parameter(Mandatory=$true)]
[int] $MaxTreads = 4
)
<#
.SYNOPSIS
A powershell script to run Microsoft Data Migration tool in command mode (DmaCmd)
.REQUIREMENTS
MS Data Migration Assistant installed
- https://www.microsoft.com/en-us/download/confirmation.aspx?id=53595
- https://blogs.msdn.microsoft.com/datamigration/2016/10/25/data-migration-assistant-configuration-settings/
Powershell module SQLSERVER or SQLPS
.DESCRIPTION
Script take 6 mandatory parameters,
- Projectname
- SQLInstanceListLocation
- ResultOutputPath Full path
- OutputFormat Save result as JSON
- Target Validate against SQL Server 2016/2017/2019 on windows, Azure SQL Database managed instance or SQL Azure Database
- MaxTreads Number of simultaneous analyzing SQL Instances
.NOTES
Auther: Lucient Denmark
Torben Schou (tschou@lucient.com)
.SAMPLE
.\RunMigration.ps1 -ProjectName "LucientQMigration" -SQLInstanceListLocation "C:\temp\myServers.csv" -ResultOutputPath "C:\result\" -OutputFormat "JSON" -Target "Choose from List" -MaxTreads 1
.\RunMigration.ps1 -ProjectName "LucientMigration" -SQLInstanceListLocation "C:\temp\myservers.csv" -ResultOutputPath "C:\temp\" -OutputFormat "JSON" -Target "SqlServer2016" -MaxTreads 1
#>
Clear-Host
#Build process file
$runTime = Get-Date -Format "yyyyMMdd-HHmm"
$Global:file = $ResultOutputPath + "ScriptStatus_"+ $runTime +".txt"
New-Item $Global:file -ItemType file -Force
If ($PSVersionTable.PSVersion.Major -lt 5)
{
Write-Host "Please ensure that PowerShell version are 5+" -ForegroundColor Red -BackgroundColor Yellow
$message = "PowerShell version is "+ $PSVersionTable.PSVersion.Major +" upgrade to version 5+"
Add-Content $Global:file $message
break;
}
if (!(Get-Module -ListAvailable -Name SQLSERVER))
{
Write-Host "Please ensure that PowerShell module SqlServer are installed" -ForegroundColor Red -BackgroundColor Yellow
Write-Host "Try running command >> Install-Module -Name SQLSERVER -Force <<" -ForegroundColor Red -BackgroundColor Yellow
$message = "PowerShell module SqlServer is not installed"
Add-Content $Global:file $message
break;
}
$MyDir = Get-Location
$no = 0
Function CallDWM ($Target, $SQLInstanceListLocation, $ProjectName, $ResultOutputPath, $OutputFormat, $MaxTreads)
{
if (Import-Csv $SQLInstanceListLocation)
{
Import-Csv $SQLInstanceListLocation | ForEach-Object{
$SQLInstance = $_.Server
$cmd = ".\DataMigration.ps1 -ProjectName '$ProjectName' -SQLInstance '$SQLInstance' -ResultOutputPath '$ResultOutputPath' -Target '$Target' -Output '$OutputFormat' -ErrorReport '$Global:file' -ErrorAction SilentlyContinue"
Invoke-Expression $cmd -ErrorAction Stop
Write-Host "Processing SQL Instance $SQLInstance Migration target are $Target" -BackgroundColor Yellow -ForegroundColor Blue
While($(gps | ? {$_.mainwindowtitle.length -ne 0} | Where-object {$_.name -eq 'DmaCmd'}).Count -ge $MaxTreads)
{
Start-Sleep -s 30
}
}
} else {
Write-Host "The SQL Server instance list file - $SQLInstanceListLocation isn't correct!" -ForegroundColor Red
Write-Host "Correct format is" -ForegroundColor Yellow
Write-Host "-----------------" -ForegroundColor Yellow
Write-Host "Server " -ForegroundColor Green
Write-Host "tsc\maps " -ForegroundColor Green
Write-Host "tsc\my2017 " -ForegroundColor Green
Start-Process Notepad.exe $SQLInstanceListLocation
break;
}
}
switch ($Target)
{
"SqlServer2016"
{
CallDWM "SqlServer2016" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
}
"SqlServerWindows2017"
{
CallDWM "SqlServerWindows2017" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
}
"SqlServerWindows2019"
{
CallDWM "SqlServerWindows2019" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
}
"AzureSqlDatabase"
{
CallDWM "AzureSqlDatabase" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
}
"ManagedSqlServer"
{
CallDWM "ManagedSqlServer" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
}
"All_5"
{
CallDWM "SqlServer2016" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
Start-Sleep -Seconds 15
CallDWM "SqlServerWindows2017" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
Start-Sleep -Seconds 15
CallDWM "SqlServerWindows2019" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
Start-Sleep -Seconds 15
CallDWM "AzureSqlDatabase" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
Start-Sleep -Seconds 15
CallDWM "ManagedSqlServer" $SQLInstanceListLocation $ProjectName $ResultOutputPath $OutputFormat $MaxTreads
}
}