Sql-server – Is it normal for Install-Module SqlServer to clobber existing modules

powershellsql server

I have a windows 10 box with SSMS 17. I had SSMS 2016 installed, but it is now uninstalled. When I go to install the SqlServer module I get this warning:

C:\WINDOWS\system32> install-module sqlserver -Scope AllUsers

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy
value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PackageManagement\Install-Package : The following commands are already available on this system:'Add-RoleMember,Add-SqlAvailabilityDatabase,Add-SqlAvailabilityGroupListenerStaticIp,Add-SqlAzu
reAuthenticationContext,Add-SqlColumnEncryptionKeyValue,Add-SqlFirewallRule,Add-SqlLogin,Backup-ASDatabase,Backup-SqlDatabase,Complete-SqlColumnMasterKeyRotation,ConvertFrom-EncodedSqlName,Co
nvertTo-EncodedSqlName,Convert-UrnToPath,Disable-SqlAlwaysOn,Enable-SqlAlwaysOn,Get-SqlAgent,Get-SqlAgentJob,Get-SqlAgentJobHistory,Get-SqlAgentJobSchedule,Get-SqlAgentJobStep,Get-SqlAgentSch
edule,Get-SqlColumnEncryptionKey,Get-SqlColumnMasterKey,Get-SqlCredential,Get-SqlDatabase,Get-SqlErrorLog,Get-SqlInstance,Get-SqlLogin,Get-SqlSmartAdmin,Grant-SqlAvailabilityGroupCreateAnyDat
abase,Invoke-ASCmd,Invoke-PolicyEvaluation,Invoke-ProcessASDatabase,Invoke-ProcessCube,Invoke-ProcessDimension,Invoke-ProcessPartition,Invoke-ProcessTable,Invoke-Sqlcmd,Invoke-SqlColumnMaster
KeyRotation,Join-SqlAvailabilityGroup,Merge-Partition,New-RestoreFolder,New-RestoreLocation,New-SqlAvailabilityGroup,New-SqlAvailabilityGroupListener,New-SqlAvailabilityReplica,New-SqlAzureKe
yVaultColumnMasterKeySettings,New-SqlBackupEncryptionOption,New-SqlCertificateStoreColumnMasterKeySettings,New-SqlCngColumnMasterKeySettings,New-SqlColumnEncryptionKey,New-SqlColumnEncryption
KeyEncryptedValue,New-SqlColumnEncryptionSettings,New-SqlColumnMasterKey,New-SqlColumnMasterKeySettings,New-SqlCredential,New-SqlCspColumnMasterKeySettings,New-SqlHADREndpoint,Read-SqlTableDa
ta,Read-SqlViewData,Remove-RoleMember,Remove-SqlAvailabilityDatabase,Remove-SqlAvailabilityGroup,Remove-SqlAvailabilityReplica,Remove-SqlColumnEncryptionKey,Remove-SqlColumnEncryptionKeyValue
,Remove-SqlColumnMasterKey,Remove-SqlCredential,Remove-SqlFirewallRule,Remove-SqlLogin,Restore-ASDatabase,Restore-SqlDatabase,Resume-SqlAvailabilityDatabase,Revoke-SqlAvailabilityGroupCreateA
nyDatabase,Save-SqlMigrationReport,Set-SqlAuthenticationMode,Set-SqlAvailabilityGroup,Set-SqlAvailabilityGroupListener,Set-SqlAvailabilityReplica,Set-SqlAvailabilityReplicaRoleToSecondary,Set
-SqlColumnEncryption,Set-SqlCredential,Set-SqlErrorLog,Set-SqlHADREndpoint,Set-SqlNetworkConfiguration,Set-SqlSmartAdmin,Start-SqlInstance,Stop-SqlInstance,Suspend-SqlAvailabilityDatabase,Swi
tch-SqlAvailabilityGroup,Test-SqlAvailabilityGroup,Test-SqlAvailabilityReplica,Test-SqlDatabaseReplicaState,Test-SqlSmartAdmin,Write-SqlTableData'. This module 'SqlServer' may override the
existing commands. If you still want to install this module 'SqlServer', use -AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : CommandAlreadyAvailable,Validate-ModuleCommandAlreadyAvailable,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Is this normal or did something not uninstall right? I'm wondering if this is causing some issues I'm having with Set-ColumnEncryption.

I had trouble with the initial install of 2017, but then I had to delete a folder that the SSMS 2016 uninstaller did not install. I'm not sure what that folder was and can't' find a link to the fix I originally found.

I don't appear to have an old version of SqlServer installed as two people have suggested.

Loading personal and system profiles took 19921ms.
C:\WINDOWS\system32> import-module sqlserver
import-module : The specified module 'sqlserver' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ import-module sqlserver
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (sqlserver:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

C:\WINDOWS\system32> Get-Module sqlserver -ListAvailable
C:\WINDOWS\system32>

I do however, have SQLPS modules.

C:\WINDOWS\system32> Get-Module sqlps -ListAvailable


    Directory: C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.0        SQLPS                               {Backup-SqlDatabase, Save-SqlMigrationReport, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp...}


    Directory: C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   14.0       SQLPS                               {Backup-SqlDatabase, Save-SqlMigrationReport, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp...}


C:\WINDOWS\system32>

Best Answer

This is likely left over from SSMS 2016 in the sense that included the sqlserver module, but MS was not placing it in version folders. Which modules from the PSGallery generally do now.

If you check Get-Module sqlserver -ListAvailable | select name, version, modulebase you will see which path they go to.

I have SSMS 2016, SSMS 17 and the sqlserver module from the PSGallery installed on my Windows 10 machine.

enter image description here

You can see that the 20.0 is just dumped inside of the SqlServer module folder. I did get the error you did when I installed the module from the PSGallery, which is to be expected since the functions are the same name.

Your option would be to remove the older version that came with SSMS 2016 or just use the -AllowClobber, which will be fine.

Related Question