Skip to content

Commit 8be96c9

Browse files
Adding versioning to Login migration console app (#23988)
1 parent 82ac411 commit 8be96c9

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

src/DataMigration/DataMigration.Autorest/custom/Cmdlets/New-AzDataMigrationLoginsMigration.ps1

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,59 @@ function New-AzDataMigrationLoginsMigration
9191
#Testing Whether Console App is downloaded or not
9292
$TestExePath = Test-Path -Path $ExePath;
9393

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";
97+
9498
#Downloading and extracting LoginsMigration Zip file
9599
if(-Not $TestExePath)
96100
{
97-
$ZipSource = "https://sqlassess.blob.core.windows.net/app/LoginsMigration.zip";
98-
$ZipDestination = Join-Path -Path $BaseFolder -ChildPath "LoginsMigration.zip";
101+
#Downloading and extracting LoginMigration Zip file
102+
Write-Host "Downloading and extracting latest LoginMigration Zip file..."
99103
Invoke-RestMethod -Uri $ZipSource -OutFile $ZipDestination;
100-
101104
Expand-Archive -Path $ZipDestination -DestinationPath $BaseFolder -Force;
102105
}
106+
else
107+
{
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)
123+
{
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;
129+
130+
# Remove existing folder and contents
131+
$ConsoleAppDestination = Join-Path -Path $BaseFolder -ChildPath "Logins.Console.csproj";
132+
Remove-Item -Path $ConsoleAppDestination -Recurse;
133+
134+
# Remove version file
135+
Remove-Item -Path $VersionFileDestination;
136+
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+
}
146+
}
103147

104148
#Collecting data
105149
if(('CommandLine') -contains $PSCmdlet.ParameterSetName)

0 commit comments

Comments
 (0)