dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

[Bug] cleanup.ps1 script is removing the latest version

Open sequeltom opened this issue 6 years ago • 6 comments

Environmental information


#### PowerShell version:

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.18362.628                                                                           
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.18362.628                                                                          
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 




#### dbatools Module version:


Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\1.0.104\dbatools.psd1
Version : 1.0.104

Name    : dbatools
Path    : C:\Program Files\WindowsPowerShell\Modules\dbatools\1.0.101\dbatools.psd1
Version : 1.0.101

SQL Server:

Not Applicable

Report

As of 1.0.104, the cleanup.ps1 script is deleting itself (the whole current module) along with the old versions.

Host used

  • [X] powershell.exe
  • [ ] ISE
  • [ ] VS Code
  • [ ] Other (please specify)

If anything other than powershell.exe was used, please confirm that you can duplicate the issue with powershell.exe

  • [ ] Still buggy in powershell.exe

Errors Received

Steps to Reproduce

Have two or more versions of dbatools installed

Install-Module -Name dbatools -RequiredVersion 1.0.101
Install-Module -Name dbatools -RequiredVersion 1.0.104

Then run the latest cleanup.ps1 from 1.0.104

& "$((Get-InstalledModule dbatools).InstalledLocation)\cleanup.ps1"

Expected Behavior

Remove 1.0.101 but leave 1.0.104

Actual Behavior

Both 1.0.101 and 1.0.104 are gone, leaving no dbatools :(

I think this relates to PR #6447. Something seems off with the semantic versioning comparison. I ran this through the debugger and the problem seems to be at line 39

$olderVersions = $installedVersion | Where-Object [version]Version -lt [version]$newestVersion.Version

The Where-Object is returning both 1.0.101 and 1.0.104 in this example and then they get deleted.

sequeltom avatar Apr 03 '20 20:04 sequeltom

@ben-thul I think made that changed and recall had tested it, showing it worked.

wsmelton avatar Apr 03 '20 20:04 wsmelton

#6447 for reference.

ben-thul avatar Apr 03 '20 21:04 ben-thul

Hi @ben-thul - I saw that PR and mentioned in the report. I was able to reproduce this behavior on a couple different Windows machines. Install two or more versions including 104, run cleanup, removes all versions of dbatools.

sequeltom avatar Apr 03 '20 22:04 sequeltom

So it is not putting the latest back on the machine?

wsmelton avatar Apr 04 '20 14:04 wsmelton

Correct, it doesn't go into the elseif that does the Install-Module. This is for the scenario where latest version is found and older versions are also found.

sequeltom avatar Apr 04 '20 15:04 sequeltom

I had some time to debug this further today. Added a fix in PR#6462 and posted a bunch of details in there.

sequeltom avatar Apr 07 '20 20:04 sequeltom