简体   繁体   English

Powershell 导入模块 SqlServer 和 SQLPS 不相处

[英]Powershell Import-Module SqlServer and SQLPS dont get along

In a current Powershell session i am running the following commands在当前的 Powershell 会话中,我正在运行以下命令

Import-Module SqlServer
Import-Module SQLPS

The Import-Module Command for SqlServer works fine, but Import-Module command for SQLPS fails SqlServer 的导入模块命令工作正常,但 SQLPS 的导入模块命令失败

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.我曾尝试使用 Remove-Module 命令删除 SqlServer 模块,但没有成功。 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).我有一个脚本,它在开始时导入 SqlServer 模块,然后脚本中有某些任务正在使用 SQLPS 模块(并且它因上述错误而失败)。 I am guessing that these 2 modules cannot be loaded in the same powershell session.我猜这两个模块不能在同一个 powershell 会话中加载。

SQLPS is the older version of the SQLServer module and you are correct; SQLPS 是 SQLServer 模块的旧版本,您是对的; the two are incompatible .两者不相容 The SQLServer module is intended to replicate all functionality from the older version, however.然而,SQLServer 模块旨在复制旧版本的所有功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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