@@ -78,77 +78,66 @@ function New-AzDataMigrationLoginsMigration
78
78
# Defining Default Output Path
79
79
$DefaultOutputFolder = Get-DefaultLoginMigrationsOutputFolder
80
80
81
- # Defining Base and Exe paths
82
- $BaseFolder = Join-Path - Path $DefaultOutputFolder - ChildPath Downloads;
83
- $ExePath = Join-Path - Path $BaseFolder - ChildPath Logins.Console.csproj\Logins.Console.exe ;
81
+ # Defining Downloads folder
82
+ $DownloadsFolder = Join-Path - Path $DefaultOutputFolder - ChildPath Downloads;
84
83
85
- # Checking if BaseFolder Path is valid or not
86
- if (-Not (Test-Path $BaseFolder ))
84
+ # Checking if DownloadsFolder Path is valid or not
85
+ if (-Not (Test-Path $DownloadsFolder ))
87
86
{
88
- $null = New-Item - Path $BaseFolder - ItemType " directory"
87
+ $null = New-Item - Path $DownloadsFolder - ItemType " directory"
88
+ }
89
+ else
90
+ {
91
+ # Delete old Login console app files
92
+ Delete- OldLoginConsoleApp $DownloadsFolder ;
89
93
}
90
94
91
- # Testing Whether Console App is downloaded or not
92
- $TestExePath = Test-Path - Path $ExePath ;
93
-
94
- # Console app download address
95
- $ZipSource = " https://sqlassess.blob.core.windows.net/app/LoginsMigration.zip" ;
96
- $ZipDestination = Join-Path - Path $BaseFolder - ChildPath " LoginsMigration.zip" ;
95
+ # Determine latest version of Login console app
96
+ $PackageId = " Microsoft.SqlServer.Migration.LoginsConsoleApp"
97
+ $LatestNugetOrgDetails = Get-LatestConsoleAppVersionFromNugetOrg $PackageId
97
98
98
- # Downloading and extracting LoginsMigration Zip file
99
- if (-Not $TestExePath )
99
+ # Determine local version of Login console app
100
+ $ConsoleAppFolders = Get-ChildItem - Path $DownloadsFolder - Filter " $PackageId .*"
101
+ $LatestLocalNameAndVersion = " "
102
+ if ($ConsoleAppFolders.Length -gt 0 )
100
103
{
101
- # Downloading and extracting LoginMigration Zip file
102
- Write-Host " Downloading and extracting latest LoginMigration Zip file..."
103
- Invoke-RestMethod - Uri $ZipSource - OutFile $ZipDestination ;
104
- Expand-Archive - Path $ZipDestination - DestinationPath $BaseFolder - Force;
104
+ $ConsoleAppFolders = $ConsoleAppFolders | Sort-Object - Property Name - Descending
105
+ $LatestLocalNameAndVersion = $ConsoleAppFolders [0 ].Name
106
+ Write-Host " Installed Login migration console app nupkg version: $LatestLocalNameAndVersion "
107
+
108
+ if ($AvailablePackagesOnNugetOrg -eq " " )
109
+ {
110
+ $LatestNugetOrgDetails.NameAndVersion = $LatestLocalNameAndVersion
111
+ }
105
112
}
106
113
else
107
114
{
108
- # Get local exe version
109
- Write-Host " Checking installed Login.Console.exe version..." ;
110
- $installedVersion = (Get-Item $ExePath ).VersionInfo.FileVersion;
111
- Write-Host " Installed version: $installedVersion " ;
112
-
113
- # Get latest console app version
114
- Write-Host " Checking whether there is newer version..." ;
115
- $VersionFileSource = " https://sqlassess.blob.core.windows.net/app/loginconsoleappversion.json" ;
116
- $VersionFileDestination = Join-Path - Path $BaseFolder - ChildPath " loginconsoleappversion.json" ;
117
- Invoke-RestMethod - Uri $VersionFileSource - OutFile $VersionFileDestination ;
118
- $jsonObj = Get-Content $VersionFileDestination | Out-String | ConvertFrom-Json ;
119
- $latestVersion = $jsonObj.version ;
120
-
121
- # Compare the latest exe version with the local exe version
122
- if ([System.Version ]$installedVersion -lt [System.Version ]$latestVersion )
115
+ # No local console app
116
+ if ($AvailablePackagesOnNugetOrg -eq " " )
123
117
{
124
- Write-Host " Found newer version of Logins.Console.exe ' $latestVersion ' " ;
125
-
126
- Write-Host " Removing old Logins.Console.exe... "
127
- # Remove old zip file
128
- Remove-Item - Path $ZipDestination ;
118
+ # No version available to download
119
+ Write-Host " Connection to NuGet.org required. Please check connection and try again. "
120
+ return ;
121
+ }
122
+ }
129
123
130
- # Remove existing folder and contents
131
- $ConsoleAppDestination = Join-Path - Path $BaseFolder - ChildPath " Logins.Console.csproj " ;
132
- Remove-Item - Path $ConsoleAppDestination - Recurse ;
124
+ Write-Host " Latest Login migration console app nupkg version on Nuget.org: $ ( $LatestNugetOrgDetails .NameAndVersion ) " ;
125
+ $LatestNugetFolder = Join-Path - Path $DownloadsFolder - ChildPath $LatestNugetOrgDetails .NameAndVersion ;
126
+ $ExePath = " tools\Microsoft.SqlServer.Migration.Logins.ConsoleApp.exe " ;
133
127
134
- # Remove version file
135
- Remove-Item - Path $VersionFileDestination ;
128
+ # Check for the latest console app version and download it if needed.
129
+ CheckAndDownloadConsoleAppFromNugetOrg $LatestLocalNameAndVersion $LatestNugetOrgDetails $ExePath ([ ref ] $LatestNugetFolder )
136
130
137
- # Downloading and extracting LoginMigration Zip file
138
- Write-Host " Downloading and extracting latest LoginMigration Zip file..."
139
- Invoke-RestMethod - Uri $ZipSource - OutFile $ZipDestination ;
140
- Expand-Archive - Path $ZipDestination - DestinationPath $BaseFolder - Force;
141
- }
142
- else
143
- {
144
- Write-Host " Installed Logins.Console.exe is the latest one..." ;
145
- }
131
+ if (-Not (Test-Path - Path " $LatestNugetFolder \$ExePath " ))
132
+ {
133
+ Write-Host " Failed to locate executable."
134
+ return
146
135
}
147
136
148
137
# Collecting data
149
138
if ((' CommandLine' ) -contains $PSCmdlet.ParameterSetName )
150
139
{
151
- # The array list $splat contains all the parameters that will be passed to '.\Logins.Console .exe LoginsMigration'
140
+ # The array list $splat contains all the parameters that will be passed to '.\Microsoft.SqlServer.Migration. Logins.ConsoleApp .exe LoginsMigration'
152
141
153
142
$LoginsListArray = $ ($ListOfLogin -split " " )
154
143
[System.Collections.ArrayList ] $splat = @ (
@@ -173,7 +162,10 @@ function New-AzDataMigrationLoginsMigration
173
162
174
163
}
175
164
}
176
- # Running LoginsMigration
165
+
166
+ $ExePath = Join-Path - Path $LatestNugetFolder - ChildPath $ExePath ;
167
+ # Running LoginsMigration
168
+ Write-Host " Starting Execution..."
177
169
& $ExePath LoginsMigration @splat
178
170
}
179
171
else
0 commit comments