简体   繁体   中英

Powershell Import-Module SqlServer and SQLPS dont get along

In a current Powershell session i am running the following commands

Import-Module SqlServer
Import-Module SQLPS

The Import-Module Command for SqlServer works fine, but Import-Module command for SQLPS fails

PS C:\windows\system32> Import-Module SqlServer
PS C:\windows\system32> Import-Module SQLPS
Import-Module : The following error occurred while loading the extended type data file: Error in TypeData
"Microsoft.SqlServer.Management.Smo.NamedSmoObject": The member DefaultKeyPropertySet is already present.
Error in TypeData "Microsoft.SqlServer.Management.Smo.NamedSmoObject": The member DefaultDisplayPropertySet is already
present.
Error in TypeData "Microsoft.SqlServer.Management.Smo.NamedSmoObject": The member DefaultDisplayProperty is already
present.
At line:1 char:1
+ Import-Module SQLPS
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

I have tried removing the SqlServer module using Remove-Module command but no luck. I have a script which is Importing the SqlServer module at the start and then there are certain tasks in the script for which the SQLPS module is being used (and it fails with the above error). I am guessing that these 2 modules cannot be loaded in the same powershell session.

SQLPS is the older version of the SQLServer module and you are correct; the two are incompatible . The SQLServer module is intended to replicate all functionality from the older version, however.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM