SQLPS不同版本的差异

服务器上装了SQL Server 2014的默认实例,以及SQL Server 2017的命名实例SQL2017

铜川ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

$env:PSModulePath为

%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\

在执行Powershell命令

New-SqlAvailabilityGroup -Name $AgName -InputObject $Primary -AvailabilityReplica $Replicas -Database $DatabaseList

时,报错如下:

SQLPS不同版本的差异

SQLPS不同版本的差异

去掉了SQL Server 2014的SQLPS目录路径

%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\

再加载SQL Server 2017默认的SQLPS,执行New-SqlAvailabilityGroup正常。

说明两个版本SQLPS里New-SqlAvailabilityGroup对应的参数-InputObject类型有差异。

后记:

后来再尝试加载SQL Server 2014的SQLPS模块,针对SQL Server 2014默认实例创建AG失败。索性直接调用新装的SqlServer模块,可以向后兼容。

Powershell模块安装

#https://www.powershellgallery.com

#在线下载安装

Install-Module -Name Powershellget -force

#离线下载安装

#https://www.powershellgallery.com/packages/CredentialsManager/1.1

#保存模块

Save-Module -Name CredentialsManager -Path C:\powershellgallery

#拷贝到

%ProgramFiles%/WindowsPowershell/Module/

#加载即用、用时注册

Import-Module -Name CredentialsManager

PowerShell 2.0 uses the appropriately-named Import-Module cmdlet to import modules. When this cmdlet is run, Windows PowerShell searches for the specified module within the directories specified in the PSModulePath variable. When the specified directory is found, Windows PowerShell searches for files in the following order: module manifest files (.psd1), script module files (.psm1), binary module files (.dll). For more information about adding directories to the search, see Modifying the PSModulePath Installation Path.

Beginning in Windows PowerShell 3.0, modules are imported automatically when any cmdlet or function in the module is used in a command. This feature works on any module in a directory that this included in the value of the PSModulePathenvironment variable. If you do not save your module on a valid path however, you can still load them using the explicit Import-Module option, described above.


标题名称:SQLPS不同版本的差异
地址分享:http://csruizhi.cn/article/gspheg.html

其他资讯

Copyright © 2007-2024 成都优众联杰科技有限公司 All Rights Reserved 蜀ICP备2024116266号
友情链接: 四川成都网站建设 成都网站建设 成都网站设计 企业网站建设 手机网站建设套餐 网站建设推广 温江网站设计 成都网站设计 企业网站制作 营销型网站建设 网站建设方案 手机网站制作 移动网站建设 网站设计制作 成都网站建设 高端网站设计推广 重庆电商网站建设 企业网站建设公司 成都品牌网站建设 成都网站设计 成都定制网站建设 攀枝花网站设计