千家信息网

SQLPS不同版本的差异

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,服务器上装了SQL Server 2014的默认实例,以及SQL Server 2017的命名实例SQL2017$env:PSModulePath为%SystemRoot%\system32\Wind
千家信息网最后更新 2026年11月03日SQLPS不同版本的差异


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

$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

时,报错如下:

去掉了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 PSModulePath environment 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.

模块 实例 差异 版本 上装 两个 参数 后记 命令 在线下载 拷贝 新装 服务器 目录 类型 路径 在线 尝试 服务 不同 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 小米移动互联网科技园 亿人帮互联网科技有限公司 互联网科技活动banner 互联网最新的科技 新华互联网科技学院 工业互联网科技新基建 互联网科技资迅 互联网中国科技 北京互联网科技有限公司 撒么互联网科技公司 深圳国际航运科技和互联网 浙江互联网科技研学营 杭州壁岐互联网科技有限公司 工业互联网等科技实现智能化赋能 上海钢联属于互联网科技股吗 互联网营销推广黑科技 互联网科技年终奖 互联网金融运营模式中的金融科技 兰石爱特工业互联网科技分公司 杭州科技互联网公司有哪些 互联网科技海报 广州为想互联网科技有限公司 致聘互联网科技 掌上梦互联网科技 互联网科技类展会 互联网科技实习生岗位职责 福建科技产业互联网发展 知域互联网科技有限公司大骗子 深圳市优智互联网科技有限公司 互联网时代科技型公司的机会
0